Extended Precision OperationsTo represent larger numbers more bits are neededTo represent larger numbers, more bits are needed. N bits can represent the unsigned range 0 to 2N-1.BUi dRCDTBk’DBytes1 Byte = 8 bitsUnsigned RangeCData Type (PIC 24 compiler)Book’s Data type definition1 (8 bits) 0 to 255 unsigned charuint82 (16 bits) 0 to 65,535 unsigned short uint162 (16 bits) 0 to 65,535 unsigned int uint164 (32 bits) 0 to 4,294,967,295 unsigned long uint32The size of int, long depends on the C implementation; on some machines both int and long are 4 bytes, with a shortbeing 2 bytes. V 0.7 1gygyOn some machines a long is 8 bytes (64 bits).32-bit Data Moves32bit Data MovesThe term‘double word’refers to 32bit dataThe term double word refers to 32-bit data.A double word mov instruction copies 32 bits of data, 16 bits at a time.bl d ddV 0.7 2Double words must start at an even memory address.Double Word Move ExampleV 0.7 3Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Variable InitializationOrder in which the words (LSW or MSW) are initializedOrder in which the words (LSW or MSW) are initialized does not matter.LSW == Least Significant Word (lower 16-bit word)MSW Most Significant Word (upper 16bit word)V 0.7 4MSW == Most Significant Word (upper 16-bit word)Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Bitwise Logical OperationsgpOrder in which the words (LSW or MSW) are operated ()pupon does not matter for bitwise logical operations.Copyright Delmar Cengage Learning 2008. All Rights Reserved.V 0.7 5py g g g g gFrom: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32Bit Addition Subtraction32-Bit Addition, SubtractionOperation done on least significant words first.Addition of most significant words includes CARRY.Subtraction of most significant words includes BORROW (~C)Subtraction of most significant words includes BORROW (~C).Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones “Microcontrollers: From Assembly to C with the PIC24 Family”V 0.7 6From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Addition/Subtraction in Assemblyyaddc is add with carrysubb is subtract with borrowV 0.7 7Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.Other Forms of Add/Sub Extended PrecisionCopyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.V 0.7 8There is no “Compare against Zero with borrow” instruction.Z Flag Behavior in Extended PrecisionV 0.7 9Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Increment/DecrementThere are no “increment with carry” or “decrement with borrow” instructions.V 0.7 10Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Increment (again), add (again)uint32 k j;uint32 k, j;k = j+1;;2-operand approachinc j,WREG ;W0=j.lsw+1mov W0,k ;k.lsw = j.lsw+1, flags unaffectedclr W0 ;W0=0, flags unaffectedaddc k+2 ;k.msw = k.msw + 0 + C ;uses 3-operand addmov j,W0 ;W0=j.lswuint32 k, j, p;k = j+p;mov j,W0 ;W0 j.lswmov p,W1 ;W1=p.lswadd W0,W1,W0 ;W0=j.lsw+p.lswmov W0,k ;k.lsw=j.lsw+p.lswmov j+2,W0 ;W0=j.mswmov j+2,W0 ;W0 j.mswmov p+2,W1 ;W1=p.mswaddc W0,W1,W0 ;W0=j.msw + p.msw + Cmov W0,k+2 ;k.msw = j.msw + p.msw + CV 0.7 11Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Shift Right/ Shift LeftgRepeat sequence for multiple-V 0.7 12Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.position 32-bit shifts32-bit Non-Zero Test Using ComparegpCompare 32-bit K against 32-bit zero using compare, compare with borrow Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Non-Zero TestA little more efficient than the previous slide.A little more efficient than the previous slide.Bitwise OR the LSW and MSW; if result is non-zero, the 32-bit value is zero. You CANNOT just do:jmov kmov k+2in this case, Z flag is only based MSW!!!!V 0.7 14bz end_ifon MSW!!!!Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.Another Example of 32-bit TestingNote that the logical OR operation (||) has nothing to do with the fact that Bitwise OR is used for testing each 16-bit value for zero or non-that Bitwise OR is used for testing each 16bit value for zero or nonzero! If the code is if (k && !j),bitwise OR is still used for zero/non-zero V 0.7 15( j),test.Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit EqualityUtt df8/16bit t t t 32Use same structure as used for 8/16-bit tests, except use a 32-bit comparison (cp for LSW comparison, cpb for MSW comparison). The sticky ‘Z’ flag behavior enables this V 0.7 16comparison.Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to C with the PIC24 Family”.32-bit Greater-Thanuint32 k, j; mov j,W0 ;W0 = j.LSWcp k ;k LSW-jLSWInCIn Assemblyif (k > j) {if-body code} cp k ;k.LSW j.LSW mov j+2,W0 ;W0 = j.MSW cpb k+2 ;k.MSW - j.MSW bra LEU,end_if ;skip if-body when k<=jif body:}... rest of codeif_body:if-body stmt1 ... stmtNend_if:fdHas same structure as 8/16-bitcode except that a 32-bit comparisonis used.All of the if/loop structures from Chapter 4 can be used, just replace ....rest of code16-bit comparisons with 32-bit comparisons. V 0.7 17Copyright Delmar Cengage Learning 2008. All Rights Reserved.From: Reese/Bruce/Jones, “Microcontrollers: From Assembly to
View Full Document