Fall 2018/19 - Lecture Notes # 10: - Logic Instructions
Fall 2018/19 - Lecture Notes # 10: - Logic Instructions
Fall 2018/19 - Lecture Notes # 10: - Logic Instructions
8086
• Shift Instructions
XOR CH,35H
Solution: This will cause bit 2 of BL to change to the opposite value; all other bits would remain
unchanged.
EENG410: MICROPROCESSORS I
8086
Shift Instructions
▪ SHR (Shift Right) Instruction
0 MSB LSB CF
• This is the logical shift right. The dest operand is shifted right bit by bit, and for every shift
the LSB will go to the CF and MSB is filled with a zero.
•dest operand can be in a register or memory. Immediate addressing mode is not possible.
•If the dest. operand is to be shifted once only 1 can be used instead of CL.
EENG410: MICROPROCESSORS I
8086
Shift Instructions
▪ SHL (Shift Left) Instruction
CF MSB LSB 0
• SHL is also a logical shift instruction. The operand is shifted left bit by bit, and for every shift
the LSB is filled with a zero (0) and the MSB goes into CF.
Solution: 00000110
CF=0 00001100 (shifted left once)
CF=0 00011000
CF=0 00110000
CF=0 01100000 (shifted left 4 times)
After the 4 shifts DH=60H and CF=0.
• dest operand can be in a register or memory. Immediate addressing mode is not possible.
• If the dest. operand is to be shifted once only 1 can be used instead of CL.
EENG410: MICROPROCESSORS I
8086
Compare of unsigned numbers
• Compare Instructions
▪ CMP (Compare) Instruction
• Unpacked BCD: 1 byte is used to store 4 bit BCD code. E.g. 0000 1001 is unpacked BCD
for 9.
• Packed BCD: 1 byte is used to store two 4 bit BCD codes. E.g. 0101 1001 is packed BCD
for 59. More efficient in storing data. ASCII Numbers
BCD Digits Key ASCII(Hex) Binary BCD (Unpacked)
Digit BCD 0 30 011 0000 0000 0000
0 0000 1 31 011 0001 0000 0001
1 0001 2 32 011 0010 0000 0010
2 0010 3 33 011 0011 0000 0011
3 0011 4 34 011 0100 0000 0100
4 0100
5 35 011 0101 0000 0101
5 0101
6 36 011 0110 0000 0110
6 0110
7 0111 7 37 011 0111 0000 0111
8 1000 8 38 011 1000 0000 1000
9 1001 9 39 011 1001 0000 1001
EENG410: MICROPROCESSORS I
8086
BCD and ASCII Numbers
• ASCII to BCD Conversion
▪ ASCII to Unpacked BCD Conversion
➢ In order to convert ASCII to BCD the programmer must get rid of tagged “011” in
the higher four bits of the ASCII.
➢ To do that each ASCII number is ANDed with ‘0000 1111’ (0FH).
Ex: :
ASC DB ‘9562481273’
ORG 0010H
UNPACK DB 10 DUP(?)
:
MOV CX,5 ;CX is the loop counter
MOV BX,OFFSET ASC ;BX points to ASCII data
MOV DI,OFFSET UNPACK ;DI points to unpacked BCD data
AGAIN: MOV AX,WORD PTR [BX] ;move next 2 ASCII numbers to AX
AND AX,0F0FH ;remove ASCII 3s (011)
MOV WORD PTR [DI],AX ;store unpacked BCD
ADD DI,2 ;point to next unpacked BCD data
ADD BX,2 ;point to next ASCII data
LOOP AGAIN
EENG410: MICROPROCESSORS I
8086
BCD and ASCII Numbers
• ASCII to BCD Conversion
▪ ASCII to Packed BCD Conversion
➢ To convert ASCII to packed BCD, it is first converted to unpacked BCD (to get rid of
the 3) and then combined to make packed BCD.
Key ASCII Unpacked BCD Packed BCD
4 34 00000100
7 37 00000111 01000111 or 47
Ex: :
ORG 0010H
VAL_ASC DB ‘47’
VAL_BCD DB ?
:
;note that DB will put 34 in offset 0010H and 37 in 0011H.
MOV AX,WORD PTR VAL_ASC ;AH=37 AL=34
AND AX,0F0FH ;mask 3 to get unpacked BCD
XCHG AH,AL ;swap AH and AL
MOV CL,4 ;CL=04 to shift 4 times
SHL AH,CL ;shift left AH to get AH=40H
OR AL,AH ;OR them to get packed BCD
MOV VAL_BCD,AL ;save the result
EENG410: MICROPROCESSORS I
8086
BCD and ASCII Numbers
• BCD to ASCII Conversion
• Packed BCD to ASCII Conversion
➢ To convert packed BCD to ASCII, it must be first converted to unpacked and then
the unpacked BCD is tagged with 011 0000 (30H).