MyLecture11.pptx (1)
MyLecture11.pptx (1)
MyLecture11.pptx (1)
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
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
◼ 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
◼ 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