Bài giảng Vi xử lý - Chương 3: Họ vi điều khiển 8051 - 3.4 Tập lệnh 8051 - Bùi Minh Thành

Overflow Detection
• Overflow: the result is too large (or too small) to represent properly
– Example: - 8 < = 4-bit binary number <= 7
• When adding operands with different signs, overflow cannot occur!
• Overflow occurs when adding:
– 2 positive numbers and the sum is negative
– 2 negative numbers and the sum is positive
• On your own: Prove you can detect overflow by:
– Carry into MSB ° Carry out of MSB 
pdf 75 trang thamphan 27/12/2022 1380
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Vi xử lý - Chương 3: Họ vi điều khiển 8051 - 3.4 Tập lệnh 8051 - Bùi Minh Thành", để tải tài liệu gốc về máy hãy click vào nút Download ở trên.

File đính kèm:

  • pdfbai_giang_vi_xu_ly_chuong_3_ho_vi_dieu_khien_8051_3_4_tap_le.pdf

Nội dung text: Bài giảng Vi xử lý - Chương 3: Họ vi điều khiển 8051 - 3.4 Tập lệnh 8051 - Bùi Minh Thành

  1. oo ươ
  2. Y
  3. eeeo ooeoeoeee e ooeoeeeeoo eooeeeee oeoeooeyeee ooeeeoe oeeooeeee ooeoeeeoe oeeoeo oeoo oeoo
  4. add a, byte ; a  a + byte addc a, byte ; a  a + byte + C yo o
  5. SUBB A, byte subtract with borrow Example : SUBB A, #0x4F ;A  A – 4F – C Notice that There is no subtraction WITHOUT borrow. Therefore, if a subtraction without borrow is desired, it is necessary to clear the C flag. Example : Clr c SUBB A, #0x4F ;A  A – 4F
  6. 0111 1111 (positive 127) 2’s complement: 0111 0011 (positive 115) 0000 0000 00 0 1111 0010 (overflow cannot represent 242 in 8 bits 2’s complement) 0111 1111 7F 127 1000 0000 80 -128 1000 1111 (negative 113) 1101 0011 (negative 45) 0110 0010 (overflow) 1111 1111 FF -1 0011 1111 (positive) 1101 0011 (negative) 0001 0010 (never overflows)
  7. C 1234 40H, 41H + 5678 42H, 43H (AC) 112 6912
  8. Y o YY yye Y ye ye yyeo Y
  9. DEC byte ;byte=byte-1 INC byte ;byte=byte+1 INC R7 DEC A DEC 40H ; [40]=[40]-1
  10. eeeo eo o eeeeoe o o ooye o
  11. o
  12. eo Examples: ANL  AND 00001111 ANL 10101100 ORL  OR 00001100 XRL  XOR 00001111 CPL  Complement ORL 10101100 10101111 00001111 XRL 10101100 10100011 CPL 10101100 01010011
  13. Uses of Logic Instructions oeooeoe anl PSW, #0xE7 ;PSW AND 11100111 oe orl PSW, #0x18 ;PSW OR 00011000 oee xrl P1, #0x40 ;P1 XRL 01000000
  14. 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
  15. Rotate oeooee oy o RL a Mov a,#0xF0 ; a  11110000 RR a ; a  11100001 RR a Mov a,#0xF0 ; a  11110000 RR a ; a  01111000
  16. Swap SWAP a mov a, #72h ; a  27h swap a ; a  27h
  17. e oe oeoe oeo e e
  18. eeo
  19. yeo µ
  20. yo yo yo
  21. ưO
  22. ooe Y
  23. eeooeoeoooeo oeeoeoeooee oeeoeoeoyoooo oeeeooee eoo eeeoeoeoyoee eeoo oo OA O O O O
  24. oo
  25. ooeeo oeo e e e oe e e e oe e eee
  26. o oe eooe eoe oe o e oee e
  27. oo o o JZ JNZ JC JNC JB , JNB , JBC , e CJNE A, direct, oeeoy oe
  28. eoooyeye ooeooeye eeeo oo EA O AA OAA EAA Ooo
  29. eeeeoeeeeo eooeeee oo EA OAA OAA EAEAA Ooo
  30. eeoo ooo For A = 4 to 0 do { } clr a mov R0, #4 loop: loop: inc a cjne a , #4, loop djnz R0, loop
  31. eooeo ooooo oo O O O Oo Oo Ooo
  32. oe oeoeye eo eo e
  33. o ơoyye yoo o yo o yo yo o
  34. : ơo o o O O o O A oA OO O Aưươ A E AE ư OE E A A A OO OE O O E