Arithmetic Instructions
Arithmetic Instructions
Subtraction Instructions
◦ SUB, SBB, DEC, AAS, DAS, and NEG
25
Arithmetic Instructions
Subtraction Instructions
◦ SUB, SBB, DEC, AAS, DAS, and NEG
Allowed operands for SUB and SBB
instructions
Allowed operands Allowed operands
for DEC instruction for NEG instruction
26
Arithmetic Instructions
Subtraction Instructions
◦ EXAMPLE:
Assuming that the contents of register BX and CX are 123416
and 012316, respectively, and the carry flag is 0, what is the result
of executing the instruction SBB BX, CX?
◦ Solution:
(BX)-(CX)-(CF) (= (BX)
We get
(BX) = 123416 – 012316 – 016
= 111116
the carry flag remains cleared
27
Arithmetic Instructions
Subtraction Instructions
◦ EXAMPLE:
Assuming that the register BX contains 003A16, what is the
result of executing the following instruction?
NEG BX
◦ Solution:
(BX) = 000016-(BX)=000016+2’complement of 003A16
= 000016+FFC616
= FFC616
Since no carry is generated in this add operation, the carry flag is
complemented to give (CF) = 1
28
Arithmetic Instructions
DAA/DAS Instructions
◦ DAA
If the lower nibble is greater than 9, after addition or if AF is
set, it will add 06 to the lower nibble in AL.
After adding 06 in the lower nibble of AL, if the upper nibble of
AL is greater than 9 or if carry flag is set, DAA instruction adds
60H to AL.
29
Arithmetic Instructions
DAA/DAS Instructions
◦ DAS
30
Arithmetic Instructions
Subtraction Instructions
◦ EXAMPLE:
Perform a 32-bit binary subtraction for variable X and Y
◦ Solution:
31
Arithmetic Instructions
Multiplication & Division Instructions
◦ MUL, DIV, IMUL, IDIV, AAM, AAD, CBW, and CWD
32
Arithmetic Instructions
Multiplication & Division Instructions
◦ MUL, DIV, IMUL, IDIV, AAM, AAD, CBW, and CWD
Allowed operands
33
Arithmetic Instructions
Multiplication & Division Instructions
◦ EXAMPLE:
The 2’s-complement signed data contents of AL are –1 and that
of CL are –2. What result is produced in AX by executing the
following instruction?
MUL CL and IMUL CL
◦ Solution:
(AL) = -1 (as 2’s complement) = 111111112 = FF16
(CL) = -2 (as 2’s complement) = 111111102 = FE16
Executing the MUL instruction gives
(AX) = 111111112x111111102=11111101000000102=FD0216
Executing the IMUL instruction gives
(AX) = -116 x -216 = 216 = 000216
34
Arithmetic Instructions
Multiplication & Division Instructions
◦ EXAMPLE:
What is the result of executing the following instructions?
MOV AL, 0A1H
CBW
CWD
◦ Solution:
(AL) = A116 = 101000012
Executing the CBW instruction extends the MSB of AL
(AH) = 111111112 = FF16 or (AX) = 11111111101000012
Executing the CWD instruction, we get
(DX) = 11111111111111112 = FFFF16
That is, (AX) = FFA116 (DX) = FFFF16 35