Download presentation

Presentation is loading. Please wait.

Published byEstevan Rampton Modified over 2 years ago

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

2
Integer Types

3
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 240204D2 addiu v0,zero,1234 9D000010 AFC20000 sw v0,0(s8) 13: j = 5678; 9D000014 2402162E addiu v0,zero,5678 9D000018 AFC20004 sw v0,4(s8) 14: k = i*j; 9D00001C 8FC30000 lw v1,0(s8) 9D000020 8FC20004 lw v0,4(s8) 9D000024 70621002 mul v0,v1,v0 9D000028 AFC20008 sw v0,8(s8)

4
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) 9D000030 8FC20008 lw v0,8(s8) 9D000034 00620019 multu v1,v0 9D000038 00002012 mflo a0 9D00003C 00002810 mfhi a1 9D000040 8FC30000 lw v1,0(s8) 9D000044 8FC2000C lw v0,12(s8) 9D000048 70621802 mul v1,v1,v0 9D00004C 00A01021 addu v0,a1,zero 9D000050 00431021 addu v0,v0,v1 9D000054 8FC60008 lw a2,8(s8) 9D000058 8FC30004 lw v1,4(s8) 9D00005C 70C31802 mul v1,a2,v1 9D000060 00431021 addu v0,v0,v1 9D000064 00402821 addu a1,v0,zero 9D000068 AFC40010 sw a0,16(s8) 9D00006C AFC50014 sw a1,20(s8)

5
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) 9D000020 8FC20004 lw v0,4(s8) 9D000024 0062001A div v1,v0 9D000028 004001F4 teq v0,zero 9D00002C 00001012 mflo v0 9D000030 AFC20008 sw v0,8(s8)

6
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; 9D000030 8FC40010 lw a0,16(s8) 9D000034 8FC50014 lw a1,20(s8) 9D000038 8FC60018 lw a2,24(s8) 9D00003C 8FC7001C lw a3,28(s8) 9D000040 0F40001A jal 0x9d000068 9D000044 00000000 nop 9D000048 AFC20020 sw v0,32(s8) 9D00004C AFC30024 sw v1,36(s8)

7
Exploring The PIC32 - Lucio Di Jasio Floating Point Types

8
Exploring The PIC32 - Lucio Di Jasio The Simulator Stopwatch

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

10
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;

11
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;

12
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

13
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.

14
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.

Similar presentations

OK

Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.

Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on pierre simon laplace Ppt on indian retail industry 2010 Ppt on personality development for college students Ppt on autonomous car accidents Free download ppt on smart note taker Ppt on polynomials and coordinate geometry distance Ppt on septic abortion Ppt on 3 r's of environment Ppt on static circuit breaker Ppt on micro hydro power plant