MyLecture11.pptx (1)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

INSTRUCTION SET OF 8088/8086

COURSE CODE: CS-430


COURSE TITLE: MICROPROCESSOR PROGRAMMING AND INTERFACING
PREPARED BY: DR. SYED AQEEL HAIDER
REVIEW OF PREVIOUS LECTURE

◼ Introduction to Instruction Set of 8088/8086 Microprocessor


◼ Group of Instructions
◼ Data Transfer Group of Instructions
◼ Arithmetic and Logic Instructions
TO BE COVERED

◼ Arithmetic and Logic Group of Instruction


MULTIPLICATION INSTRUCTIONS

◼ IMUL / MUL S SOURCE (S)


8-BIT:
REG8
(AX) 🡨 (AL) * (S8)
REG16
16-BIT:
MEM8
(DX-AX) 🡨 (AX) * (S16)
MEM16
After MUL:
CF/OF = 0, If the upper half of the result is zero.
CF/OF = 1, otherwise.
After IMUL:
CF/OF = 0, If the upper half of the result is the sign extension of the lower half (this means that the bits of the upper half
are the same as the sign bit of the lower half)
CF/OF = 1, otherwise.
MULTIPLICATION INSTRUCTIONS

Example 1:
(AX) = 0001h, (BX) = FFFFh
After MUL BX
(DX) = 0000, (AX) = FFFFh, CF/OF = 0
After IMUL BX
(DX) = FFFFh, (AX) = FFFFh, CF/OF = 0

FFFFh = 1111111111111111
1s comp = 0000000000000000
Example 2: 2s comp = 0000000000000001 = 0001
(AX) = FFFFh, (BX) = FFFFh
After MUL BX
MULTIPLICATION INSTRUCTIONS

Example 3:
(AX) = 0FFFh, (BX) = 0FFFh
After MUL BX
(DX) = 00FFh, (AX) = E001h, CF/OF = 1
After IMUL BX
(DX) = 00FFh, (AX) = E001h, CF/OF = 1

Example 4:
(AX) = 0100h, (BX) = FFFFh
After MUL BX
DIVISION INSTRUCTIONS

◼ IDIV / DIV S SOURCE (S)


8-BIT: REG8
(AL) 🡨 Q [(AX) / (S8)] REG16
(AH) 🡨 R [(AX) / (S8)] MEM8
16-BIT: MEM16
(AX) 🡨 Q [(DX-AX) / (S16)]
(DX) 🡨 R [(DX-AX) / (S16)]
No Status Flags affected
DIVISION INSTRUCTIONS
Example 1:
MOV AX , 0020h
MOV CL , FFh
DIV CL
(AL) = 20 🡨 Q (0020) / (FF)
(AH) = 00 🡨 R (0020) / (FF)
Example 2:
MOV AX , 0020h
MOV CL , FFh
IDIV CL
(AL) = E0 🡨 Q (0020) / (FF)
(AH) = 00 🡨 R (0020) / (FF)
Example 3:
DIVISION INSTRUCTIONS
Example 5:
MOV AX , 8000h
MOV CL , 7Fh
DIV CL ; Q = 102h
(AL) = 00 🡨 Q (8000) / (7F) Division can’t be
(AH) = 80 🡨 R (8000) / (7F) performed
Example 6:
MOV AX , FFE0h
MOV CL , 20h
IDIV CL
(AL) = FF 🡨 Q (FFE0) / (20)
(AH) = 00 🡨 R (FFE0) / (20)
Example 7:
RELATION BETWEEN DIFFERENT DATA TYPES
BINARY HEXADECIMAL PACKED BCD UNPACKED BCD ASCII

0000 0 0 00 30

0001 1 1 01 31

0010 2 2 02 32

0011 3 3 03 33

0100 4 4 04 34

0101 5 5 05 35

0110 6 6 06 36

0111 7 7 07 37

1000 8 8 08 38

1001 9 9 09 39

1010 A 10 0100 3130

1011 B 11 0101 3131

1100 C 12 0102 3132

1101 D 13 0103 3133

1110 E 14 0104 3134

1111 F 15 0105 3135


BCD ARITHMETIC INSTRUCTIONS

◼ DAA Instruction:
Purpose:
This instruction corrects the result in AL of adding two packed BCD operands.
Format: DAA
Operation:
◼ If low nibble of AL is greater than 9h or if AF is set, then a 6 is added to AL and AF is set to 1.
◼ If high nibble of AL is greater than 9h or if CF is set, then 60h is added to AL and CF is set to 1.
◼ Flags affected: A,C, P, S, Z.

◼ DAS Instruction:
Purpose:
This instruction corrects the result in AL of subtracting two packed BCD operands.
BCD ARITHMETIC INSTRUCTIONS
Example 1:
MOV AL , 68h
ADD AL , 23h ; (AL) = 8Bh , AF = 0, CF = 0
DAA ; (AL) = 8B + 06 = 91h , AF = 1
Example 2:
MOV AL , 68h
ADD AL , 81h ; (AL) = E9h , AF = 0, CF = 0
DAA ; (AL) = E9 + 60 = 49h , CF = 1
Example 3:
MOV AL , 68h
ADD AL , 83h ; (AL) = EBh , AF = 0, CF = 0
DAA ; (AL) = EB + 66 = 51h , AF = 1, CF = 1
Example 4:
BCD ARITHMETIC INSTRUCTIONS
Example 7:
MOV AL , 68h
ADD AL , 29h ; (AL) = 91h , AF = 1, CF = 0
DAA ; (AL) = 91 + 06 = 97h , AF = 1
Example 8:
MOV AL , 98h
ADD AL , 81h ; (AL) = 19h , AF = 0, CF = 1
DAA ; (AL) = 19 + 60 = 79h , CF = 1
Example 9:
MOV AL , 98h
ADD AL , 89h ; (AL) = 21h , AF = 1, CF = 1
DAA ; (AL) = 21 + 66 = 87h , AF = 1, CF = 1
Example 10:
ASCII ARITHMETIC INSTRUCTIONS

◼ AAA Instruction:
Purpose:
This instruction corrects the result in AL of adding two unpacked BCD digits or two ASCII digits.
Format: AAA
Operation:
◼ If the low nibble of AL is greater than 9 or the AF is set, then a 6 is added to AL, the high nibble of AL is cleared,
and a 1 is added to AH.
◼ Both AF and CF are set if the adjustment is made. Other flags are undefined.

◼ AAS Instruction:
Purpose:
This instruction corrects the result in AL of subtracting two unpacked BCD digits or two ASCII digits.
ASCII ARITHMETIC INSTRUCTIONS

Example 1: 3 4 3 6 3 4 3 6
MOV AX , 3436h 3 8 + 3 8 -
ADD AL , 38h ; (AX) = 346Eh 3 4 6 E 3 4 F E
AAA ; 1 ↓ 6 + 1 ↓ 6 -
ADD AL , 30h 3 5 0 4 3 3 0 8
4 6 3 0 + 3 0 +
8+ 3 5 3 4 3 3 3 8

5 4

Example 2:
MOV AX , 3436h
SUB AL , 38h ; (AX) = 34FEh
ASCII ARITHMETIC INSTRUCTIONS

Example 1: 3 4 3 9 3 4 3 1
MOV AX , 3439h 3 8 + 3 8 -
ADD AL , 38h; (AX) = 3471h, AF=1 3 4 7 1 3 4 F 9
AAA ; 1 ↓ 6 + 1 ↓ 6 -
ADD AL , 30h 3 5 0 7 3 3 0 3
4 9 3 0 + 3 0 +
8+ 3 5 3 7 3 3 3 3

5 7

Example 2:
MOV AX , 3431h
SUB AL , 38h; (AX) = 34F9h, AF = 1
ASCII ARITHMETIC INSTRUCTIONS
◼ AAM Instruction:
Purpose:
This instruction converts the result of multiplying two BCD digits into unpacked BCD format. It can be used in converting
numbers lower than 100 into unpacked BCD format.
Format: AAM
Operation:
◼ The contents of AL are converted into two unpacked BCD digits and placed in AX.
◼ It divides the contents of AL by 10.
◼ The quotient, corresponding to the ten’s digit is placed in AH.
◼ The remainder, corresponding to the unit’s is placed in AL.
◼ AAD Instruction:
Purpose:
Adjust the unpacked BCD dividend in AX in preparation for division.
ASCII ARITHMETIC INSTRUCTIONS

Example: AAD:
(AX) 🡨 (AH)*10 + (AL)
MOV AX , 3837h ; Dividend in ASCII form
(AX) 🡨 8 * 10 + 7 = 0087d = 0057h
MOV BL , 33h ; Divisor in ASCII form
SUB AX , 3030h ; Dividend in Unpacked BCD form DIV BL:
(AL) 🡨 Q[(87d)/(03d)] = Q[(57h)/(03h)]
SUB BL , 30h ; Divisor in Unpacked BCD / binary form
(AL) 🡨 29d = 1Dh
AAD ; Dividend converted into hexadecimal / binary (AH) 🡨 R[(87d)/(03d)] = R[(57h)/(03h)]
(AH) 🡨 00d
DIV BL ; Division (AX)/(BL) performed
AAM ; Converting quotient in unpacked BCD form AAM:
ADD AX , 3030h ; Quotient in ASCII form (AH) 🡨 Q[(29d)/(10d)] = Q[(IDh)/(0Ah)]
(AH) 🡨 02
(AL) 🡨 R[(29d)/(10d)] = R[(1Dh)/(0Ah)]
87d / 3d = 29d (AL) 🡨 09
ROTATE INSTRUCTIONS

◼ RCR/ROR/RCL/ROL D , COUNT
C
Repeated Rotation of ‘D’ for the specified ‘COUNT’ D
ROL: F
Status Flags affected 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪
C
D
D COUNT F
RCL:
REG8 1 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪
REG16 1
C
MEM 1 D
ROR: F
REG8 CL 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪
REG16 CL C
D
MEM CL F
RCR:
🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪
ROTATE INSTRUCTIONS

Examples:
ROL AX , 1 ; Rotate Left ‘(AX)’ without Carry Flag ‘1’ times
RCL DH , 1 ; Rotate Left ‘(DH)’ with Carry Flag ‘1’ times
ROR BT1 , 1 ; Rotate Right ‘(DS:BT1)’ without Carry Flag ‘1’ times
RCR WD1 , 1 ; Rotate Right ‘(DS:WD1)’ with Carry Flag ‘1’ times
ROL DX , CL ; Rotate Left ‘(DX)’ without Carry Flag ‘(CL)’ times
RCL BH , CL ; Rotate Left ‘(BH)’ with Carry Flag ‘(CL)’ times
ROR BYTEPTR [0200h] , CL ; Rotate Right byte from ‘(DS:[0200h])’ without Carry Flag ‘(CL)’ times
RCR WORDPTR [0300h] , CL ; Rotate Right word from ‘(DS:[0300H])’ with Carry Flag ‘(CL)’ times

Where BT1 DB 8Eh


WD1 DW 30F0h
SHIFT INSTRUCTIONS

◼ SAR/SHR/SAL/SHL D , COUNT
C
Repeated Shifting of ‘D’ for the specified ‘COUNT’ SHL: D
F 🡨 0
Status Flags affected SAL:
🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪

C
D COUNT D
0 🡨 F
SHR:
REG8 1 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪
REG16 1 C
D
MEM 1 🡨 F
SAR:
REG8 CL 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪 🡪
REG16 CL
MEM CL
SHIFT INSTRUCTIONS

Examples:
SHL AX , 1 ; Shift Logical Left ‘(AX)’, ‘1’ times
SAL DH , 1 ; Shift Arithmetic Left ‘(DH)’, ‘1’ times
SHR BT1 , 1 ; Shift Logical Right ‘(DS:BT1)’, ‘1’ times
SAR WD1 , 1 ; Shift Arithmetic Right ‘(DS:WD1)’, ‘1’ times
SHL DX , CL ; Shift Logical Left ‘(DX)’, ‘(CL)’ times
SAL BH , CL ; Shift Arithmetic Left ‘(BH)’, ‘(CL)’ times
SHR BYTEPTR [0200h] , CL ; Shift logical Right byte from ‘(DS:[0200h])’, ‘(CL)’ times
SAR WORDPTR [0300h] , CL ; Shift Arithmetic Right word from ‘(DS:[0300H])’, ‘(CL)’ times

Where BT1 DB 8Eh


WD1 DW 30F0h
FLAG CONTROL INSTRUCTIONS

◼ CLC ; Clear Carry Flag, (CF) 🡨 0


◼ STC ; Set Carry Flag, (CF) 🡨 1
◼ CMC ; Complement Carry Flag, (CF) 🡨 (CF)
◼ CLI ; Clear Interrupt Flag, (IF) 🡨 0
◼ STI ; Set Interrupt Flag, (IF) 🡨 1
◼ CLD ; Clear Direction Flag, (DF) 🡨 0
◼ STD ; Set Direction Flag, (DF) 🡨 1
DATA SIZE CONVERSION INSTRUCTIONS

◼ CBW ; Convert Byte into Word , (AX)🡨 Sign extended (AL)


◼ CWD ; Convert Word into Double-Word , (DX-AX) 🡨 Sign extended (AX)
◼ CDQ ; Convert Double-Word into Quad-Word , (EDX-EAX) 🡨 Sign extended (EAX)
Example:
1. (AL) = 69h; After execution of CBW (AX) = 0069h
2. (AL) = 94h; After execution of CBW (AX) = FF94h
3. (AX) = 40F6h; After execution of CWD (DX-AX) = 000040F6h
4. (AX) = C236h; After execution of CWD (DX-AX) = FFFFC236h
THANK YOU

You might also like