Chapter 4 - NUMB3RS Learning to chose the right “types” Exploring The PIC32 - Lucio Di Jasio.

Slides:



Advertisements
Similar presentations
Chapter 4 NUMB3RS.
Advertisements

Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1.
Dale/Weems/Headington
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Simple Data Type Representation and conversion of numbers
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is a legal identifier? what.
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Data Type. Syntax Rules Recap keywords breakdoubleifsizeofvoid caseelseintstatic..... Identifiers not#me123th scanfprintf _idso_am_igedd007 Constant ‘a’‘+’
The Cn Language over view The Cn language strongly on ANSI C. So if you are familiar with ANCI it is not so tough to deal with Cn language. Basic Data.
Significant Figure Rules RulesExamples The following are always significant Non zero digits Zeros between non zero digits Zero to the right of a non zero.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Data Types Declarations Expressions Data storage C++ Basics.
Copyright © – Curt Hill Types What they do.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers.
Chapter2 Constants, Variables, and Data Types. 2.1 Introduction In this chapter, we will discuss –constants (integer, real, character, string, enum),symbolic.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
C is a high level language (HLL)
COMPUTER ORGANIZATION ARITHMETIC YASSER MOHAMMAD.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Variables, Operators, and Expressions
Integer Multiplication, Division Arithmetic shift
Morgan Kaufmann Publishers Arithmetic for Computers
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Tokens in C Keywords Identifiers Constants
Primitive and Reference Data Values
C Short Overview Lembit Jürimägi.
Floating Point Arithmetics
Fundamental Data Types
CMSC 104, Section 4 Richard Chang
Data Type.
DATA HANDLING.
Conversions of the type of the value of an expression
Data Type.
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is legal identifier? what.
Computer Arithmetic Multiplication, Floating Point
C++ Data Types Data Type
CSE 100 Data Types Declarations Displays.
Recitation 5 – 2/19/01 Outline
Chapter 3 Operators and Expressions
Fundamental Data Types
Programming Language C Language.
Morgan Kaufmann Publishers Arithmetic for Computers
Data Type.
Module 2 Variables, Data Types and Arithmetic
Variables and Constants
Presentation transcript:

Chapter 4 - NUMB3RS Learning to chose the right “types” Exploring The PIC32 - Lucio Di Jasio

Integer Types

Exploring The PIC32 - Lucio Di Jasio Long Multiplication (32-bit) main () { int i,j,k; i = 1234; // assign an initial value to i j = 5678; // assign an initial value to j k = i * j; // multiply and store the result in k } 12: i = 1234; 9D00000C D2 addiu v0,zero,1234 9D AFC20000 sw v0,0(s8) 13: j = 5678; 9D E addiu v0,zero,5678 9D AFC20004 sw v0,4(s8) 14: k = i*j; 9D00001C 8FC30000 lw v1,0(s8) 9D FC20004 lw v0,4(s8) 9D mul v0,v1,v0 9D AFC20008 sw v0,8(s8)

Exploring The PIC32 - Lucio Di Jasio Long Long Multiplication (64-bit) main () { long long i,j,k; i = 1234; // assign an initial value to i j = 5678; // assign an initial value to j k = i * j; // multiply and store the result in k } 15: k = i*j; 9D00002C 8FC30000 lw v1,0(s8) 9D FC20008 lw v0,8(s8) 9D multu v1,v0 9D mflo a0 9D00003C mfhi a1 9D FC30000 lw v1,0(s8) 9D FC2000C lw v0,12(s8) 9D mul v1,v1,v0 9D00004C 00A01021 addu v0,a1,zero 9D addu v0,v0,v1 9D FC60008 lw a2,8(s8) 9D FC30004 lw v1,4(s8) 9D00005C 70C31802 mul v1,a2,v1 9D addu v0,v0,v1 9D addu a1,v0,zero 9D AFC40010 sw a0,16(s8) 9D00006C AFC50014 sw a1,20(s8)

Exploring The PIC32 - Lucio Di Jasio Long Integer Division main () { int i, j, k; i = 1234;// assign an initial value to i j = 5678;// assign an initial value to j k = i / j; // divide and store the result in k } // main 15: k = i/j; 9D00001C 8FC30000 lw v1,0(s8) 9D FC20004 lw v0,4(s8) 9D A div v1,v0 9D F4 teq v0,zero 9D00002C mflo v0 9D AFC20008 sw v0,8(s8)

Exploring The PIC32 - Lucio Di Jasio Long Long Integer Division main () { int i, j, k; i = 1234;// assign an initial value to i j = 5678;// assign an initial value to j k = i / j; // divide and store the result in k } // main 15: k = i/j; 9D FC40010 lw a0,16(s8) 9D FC50014 lw a1,20(s8) 9D FC60018 lw a2,24(s8) 9D00003C 8FC7001C lw a3,28(s8) 9D F40001A jal 0x9d D nop 9D AFC20020 sw v0,32(s8) 9D00004C AFC30024 sw v1,36(s8)

Exploring The PIC32 - Lucio Di Jasio Floating Point Types

Exploring The PIC32 - Lucio Di Jasio The Simulator Stopwatch

Exploring The PIC32 - Lucio Di Jasio Multiplication Test Results Multiplication TestWidthCycle Count Performance relative to (Bits) Intfloat Char Integer ( char ) 861- Short Integer ( short ) Integer ( int, long ) Long Integer ( long long ) Single Precision FP ( float, double ) Double Precision FP ( long double )

Exploring The PIC32 - Lucio Di Jasio Type Conversions Implicit Integer Type Conversion Example: short s; // 16-bit int i; // 32-bit i = s; Explicit Integer Type Conversion Example: short s; // 16-bit int i;// 32-bit s = (short) i;

Exploring The PIC32 - Lucio Di Jasio Bit Fields extern unsigned int T1CON; extern union { struct { unsigned :1; unsigned TCS:1; unsigned TSYNC:1; unsigned :1; unsigned TCKPS0:1; unsigned TCKPS1:1; unsigned TGATE:1; unsigned :6; unsigned TSIDL:1; unsigned :1; unsigned TON:1; }; struct { unsigned :4; unsigned TCKPS:2; }; } T1CONbits; You can access each bit field using the “dot” notation, as in the following example : T1CONbits.TON = 1;

Exploring The PIC32 - Lucio Di Jasio Exact Width Types int8_t always an 8-bit signed type uint8_t always an 8-bit unsigned type int16_t always a 16-bit signed type uint16_t always a 16-bit unsigned type int32_t always a 32-bit signed type uint32_t always a 32-bit unsigned type int64_t always a 64-bit signed type uint64_t always a 64-bit unsigned type

Exploring The PIC32 - Lucio Di Jasio Math Libraries The MPLAB C32 compiler supports several standard ANSI C libraries including: “limits.h”, contains many useful macros defining implementation dependent limits, such as, for example, the number of bits composing a char type (CHAR_BIT) or the largest integer value (INT_MAX). “float.h”, contains similar implementation dependent limits for floating point data types, such as, for example the largest exponent for a single precision floating point variable (FLT_MAX_EXP). “math.h”, contains trigonometric functions, rounding functions, logarithms and exponentials but also many useful constants like PI or M_PI actually.

Exploring The PIC32 - Lucio Di Jasio Complex Types __complex__ float z; The variable z so defined has now a real and an imaginary part that can be individually addressed using respectively the syntax: __real__ z and __imag__ z Similarly the next declaration produces a complex variable of 32-bit integer type: __complex__ int x; Complex constants are easily created adding the suffix “ i ” or “ j ” as in the following examples: x = 2 + 3j; z = 2.0f + 3.0fj; NOTE Notice the use of a double underscore before and after the keyword complex.