0% found this document useful (0 votes)
54 views

Arithmetic Instructions

The document discusses subtraction, negation, and other arithmetic instructions in x86 assembly language. It provides examples of how instructions like SUB, NEG, MUL, and DIV operate on register operands. Worked examples demonstrate performing signed and unsigned binary arithmetic, extending register values using CBW and CWD, and decimal adjustment with DAA and DAS.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Arithmetic Instructions

The document discusses subtraction, negation, and other arithmetic instructions in x86 assembly language. It provides examples of how instructions like SUB, NEG, MUL, and DIV operate on register operands. Worked examples demonstrate performing signed and unsigned binary arithmetic, extending register values using CBW and CWD, and decimal adjustment with DAA and DAS.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

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

If the lower nibble is greater than 9, DAS will subtract 06 from


the lower nibble of AL.
If the result of subtraction sets the CF or if the upper nibble of
AL is greater than 9 , it subtructs 60H from AL.

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

You might also like