Chapter 7 LOGIC INSTRUCTIONS AND PROGRAMS Microcomputers and

  • Slides: 25
Download presentation
Chapter 7 LOGIC INSTRUCTIONS AND PROGRAMS Microcomputers and Microprocessors

Chapter 7 LOGIC INSTRUCTIONS AND PROGRAMS Microcomputers and Microprocessors

Outlines ¨ Define the truth tables for logic functions AND, OR, ¨ ¨ ¨

Outlines ¨ Define the truth tables for logic functions AND, OR, ¨ ¨ ¨ XOR Code 8051 Assembly language logic function instructions Use 8051 logic instructions for bit manipulation Use compare and jump instructions for program control Code 8051 rotate and swap instructions Code 8051 programs for ASCII and BCD data conversion

AND ANL destination, source ; dest = dest AND source X Y X AND

AND ANL destination, source ; dest = dest AND source X Y X AND Y 0 0 1 1 1

OR ORL destination, source ; dest = dest OR source X Y X AND

OR ORL destination, source ; dest = dest OR source X Y X AND Y 0 0 1 1 1 0 1 1

XOR XRL destination, source ; dest = dest XOR source X Y X AND

XOR XRL destination, source ; dest = dest XOR source X Y X AND Y 0 0 1 1 1 0 XRL A, #04 H ; EX-OR A with 0000 0100

XOR

XOR

XOR

XOR

CPL (complement accumulator) MOV A, #55 H CPL A ; now A=AAH ; 0101(55

CPL (complement accumulator) MOV A, #55 H CPL A ; now A=AAH ; 0101(55 H) becomes ; 1010 (AAH)

Compare instruction CJNE destination, source , relative address

Compare instruction CJNE destination, source , relative address

Table 7 -1: Carry Flag Setting For CJNE Instruction Compare destination > source Carry

Table 7 -1: Carry Flag Setting For CJNE Instruction Compare destination > source Carry Flag CY = 0 destination < source CY = 1 NOT_EQUAL: NEXT: CJNE …. JNC …. …. R 5, #80, NOT_EQUAL NEXT ; check R 5 for 80 ; R 5=80 ; jump if R 5>80 ; R 5<80

Rotating the bits of A right and left RR A ; rotate right A

Rotating the bits of A right and left RR A ; rotate right A MOV RR RR A, #36 H A A ; A=0011 ; A=0001 ; A=1000 ; A=1100 ; A=0110 1011 1101 0110 0011 RL A ; rotate left A

MOV A, #72 H RL A ; A=0111 0010 ; A=1110 0100 ; A=1100

MOV A, #72 H RL A ; A=0111 0010 ; A=1110 0100 ; A=1100 1001

Rotating through the carry RRC A ; rotate right through carry CLR MOV RRC

Rotating through the carry RRC A ; rotate right through carry CLR MOV RRC RRC C A, #26 H A A A ; make CY=0 ; A=0010 0110 ; A=0001 0011 CY=0 ; A=0000 1001 CY=1 ; A=1000 0100 CY=1 RLC A ; rotate left through carry

SETB MOV RLC RLC C A, #15 H A A ; make CY=1 ;

SETB MOV RLC RLC C A, #15 H A A ; make CY=1 ; A=0001 0101 ; A=0010 1010 ; A=0101 0110 ; A=1010 1100 ; A=0101 1000 CY=0 CY=1

SWAP A

SWAP A

RRC MOV …. . A P 1. 3, C ; first bit to carry

RRC MOV …. . A P 1. 3, C ; first bit to carry ; output carry as data bit ; second bit to carry ; output carry as data bit ; third bit to carry ; output carry as data bit

BCD AND ASCII APPLICATION PROGRAM

BCD AND ASCII APPLICATION PROGRAM

Packed BCD to ASCII conversion Packed BCD 29 H 0010 1001 Unpacked BCD 02

Packed BCD to ASCII conversion Packed BCD 29 H 0010 1001 Unpacked BCD 02 H & 09 H 0000 0010 & 0000 1001 ASCII 32 H & 39 H 0011 0010 & 0011 1001

ASCII to packed BCD conversion Key 4 7 ASCII 34 37 MOV ANL SWAP

ASCII to packed BCD conversion Key 4 7 ASCII 34 37 MOV ANL SWAP ORL Unpacked BCD 00000100 00000111 A, #’ 4’ R 1, #’ 7’ A, #0 FH R 1, #0 FH A A, R 1 Packed BCD 01000111 or 47 H ; A=34 H, hex for ASCII char 4 ; R 1=37 H, hex for ASCII char 7 ; mask upper nibble (A=04) ; mask upper nibble (R 1=07) ; A=40 H ; A=47 H, packed BCD