530 likes | 669 Vues
Explore the fundamentals of arithmetic operations on the 68HC12 microcontroller. This chapter covers essential topics such as addition, subtraction, multiplication, and division, along with shift and rotate instructions. Learn practical coding examples for basic operations like incrementing and decrementing, and understand how double numbers are handled in the 68HC12. Delve into the complexities of multiplication and division with various methods, including symmetric division and the use of MOD. Enhance your programming skills and optimize performance with these crucial arithmetic techniques.
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