1 / 14

Chapter 4 - NUMB3RS

Chapter 4 - NUMB3RS. Learning to chose the right “ types ”. Integer Types. 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 }.

gratia
Download Presentation

Chapter 4 - NUMB3RS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Exploring The PIC32 - Lucio Di Jasio 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

  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 You can access each bit field using the “dot” notation, as in the following example: T1CONbits.TON = 1; 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;

  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.

More Related