1 / 17

Part III

Part III. The 8051 Assembly Language Arithmetic & Logic Instructions. Subtract. Example: SUBB A, #0x4F ; A  A – 4F – C. Increment and Decrement. The increment and decrement instructions do NOT affect the C flag. Example: Increment 16-bit Word. Assume 16-bit word in R3:R2 mov a, r2

Download Presentation

Part III

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. Part III The 8051 Assembly Language Arithmetic & Logic Instructions EE/CS-352: Embedded Microcontroller Systems

  2. Subtract Example: SUBB A, #0x4F ; A  A – 4F – C EE/CS-352: Embedded Microcontroller Systems

  3. Increment and Decrement • The increment and decrement instructions do NOT affect the C flag. EE/CS-352: Embedded Microcontroller Systems

  4. Example: Increment 16-bit Word • Assume 16-bit word in R3:R2 mov a, r2 add a, #1 ; use add rather than increment to affect C mov r2, a mov a, r3 addc a, #0 ; add C to most significant byte mov r3, a EE/CS-352: Embedded Microcontroller Systems

  5. Multiply When multiplying two 8-bit numbers, the size of the maximum product is 16-bits FF x FF = FE01 (255 x 255 = 65025) MUL AB ; BA  A * B EE/CS-352: Embedded Microcontroller Systems

  6. Division Integer Division DIV AB ; divide A by B A  Quotient(A/B), B  Remainder(A/B) EE/CS-352: Embedded Microcontroller Systems

  7. Decimal Adjust DA a ; decimal adjust a Used to facilitate BCD addition. Adds “6” to either high or low nibble after an addition to create a valid BCD number. Example: EE/CS-352: Embedded Microcontroller Systems

  8. Logic Instructions Bitwise logic operations (AND, OR, XOR, NOT) Clear Rotate Swap Logic instructions do NOT affect the flags in PSW EE/CS-352: Embedded Microcontroller Systems

  9. Bitwise Logic Examples: ANL – AND ORL – OR XRL – eXclusive OR CPL – Complement 00001111 10101100 ANL 00001111 10101100 ORL 00001111 10101100 XRL 10101100 CPL EE/CS-352: Embedded Microcontroller Systems

  10. Address Modes with Logic a, byte direct, reg. indirect, reg, immediate byte, a direct byte, #constant a ANL – AND ORL – OR XRL – eXclusive oR CPL – Complement EE/CS-352: Embedded Microcontroller Systems

  11. Uses of Logic Instructions • Force individual bits low, without affecting other bits e.g. force bits 3&4 of PSW low • Force individual bits high, without affecting other bits e.g., force bits 5&7 of PSW high • Complement individual bits, without affecting other bits e.g., complement bit 6 of P1 EE/CS-352: Embedded Microcontroller Systems

  12. Other Logic Instructions • CLR - clear • RL – rotate left • RLC – rotate left through Carry • RR – rotate right • RRC – rotate right through Carry • SWAP – swap accumulator nibbles EE/CS-352: Embedded Microcontroller Systems

  13. CLR – Set all bits to 0 CLR A CLR byte (direct mode) CLR Ri (register mode) CLR @Ri (register indirect mode) EE/CS-352: Embedded Microcontroller Systems

  14. Rotate • Rotate instructions operate only on a rl a mov a, #0xF0 rl a EE/CS-352: Embedded Microcontroller Systems

  15. Rotate through Carry rrc a mov a, #0A9h add a, #14h rrc a C EE/CS-352: Embedded Microcontroller Systems

  16. Swap swap a mov a, #72h swap a EE/CS-352: Embedded Microcontroller Systems

  17. Bit Logic Operations Some logic operations can be used with single bit operands ANL C, bit ANL C, /bit ORL C, bit ORL C, /bit CLR C CLR bit CPL C CPL bit SETB C SETB bit “bit” can be any of the bit-addressable RAM locations or SFRs. EE/CS-352: Embedded Microcontroller Systems

More Related