530 likes | 657 Views
68HC12 Arithmetic. Chapter 3. 68HC12 Arithmetic. Addition and Subtraction Double Numbers Multiplication Division Shift and Rotate Instructions. Addition and Subtraction. 68HC12 code for 1+, 2+ . ; 1+ ( n -- n+1 ) ONEP LDD 0,X ADDD #1 STD 0,X RTS ; 2+ ( n -- n+2 ) TWOP
E N D
68HC12 Arithmetic Chapter 3
68HC12 Arithmetic • Addition and Subtraction • Double Numbers • Multiplication • Division • Shift and Rotate Instructions
68HC12 code for 1+, 2+ ; 1+ ( n -- n+1 ) ONEP LDD 0,X ADDD #1 STD 0,X RTS ; 2+ ( n -- n+2 ) TWOP LDD 0,X ADDD #2 STD 0,X RTS
68HC12 code for 1-, 2- ; 1- ( n -- n-1 ) ONEP LDD 0,X SUBD #1 STD 0,X RTS ; 2- ( n -- n-2 ) TWOP LDD 0,X SUBD #2 STD 0,X RTS
68HC12 Arithmetic • Addition and Subtraction • Double Numbers • Multiplication • Division • Shift and Rotate Instructions
68HC12 Arithmetic • Addition and Subtraction • Double Numbers • Multiplication • Division • Shift and Rotate Instructions
68HC11: A, B, C, D are 8 bits 16 x 16 => 32-bit product 68HC12: A, B, C, D could be 16 bits 32 x 32 => 64-bit product
68HC12 Arithmetic • Addition and Subtraction • Double Numbers • Multiplication • Division • Shift and Rotate Instructions
68HC12 Arithmetic • Addition and Subtraction • Double Numbers • Multiplication • Division • Shift and Rotate Instructions
C Bit 7 6 5 4 3 2 1 0 1 1 0 1 0 0 1 0 1 Logic Shift LeftLSL, LSLA, LSLB 0 C Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 A B LSLD
Logic Shift RightLSR, LSRA, LSRB C Bit 7 6 5 4 3 2 1 0 0 1 0 1 0 0 1 0 1 1 C Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 A B LSRD
Arithmetic Shift RightASR, ASRA, ASRB C 1 0 1 0 0 1 0 1 1
Rotate LeftROL, ROLA, ROLB C Bit 7 6 5 4 3 2 1 0 1 1 0 1 0 0 1 0 1
Rotate RightROR, RORA, RORB C Bit 7 6 5 4 3 2 1 0 1 0 1 0 0 1 0 1 1