You are on page 1of 25

Microprocessor Application Engineering

Instruction set

CI 052

8088/8086 MICROPROCESSOR PROGRAMMING


INTEGER INSTRUCTIONS AND COMPUTATIONS

7.1 Data-Transfer Instructions


7.2 Arithmetic Instructions
7.3 Logic Instructions
7.4 Shift Instructions
7.5 Rotate Instructions

02/21/15

K.Rajalakshmi,JIIT,Noida

Microprocessor Application Engineering

Instruction set

CI 052

7.1 Arithmetic Instructions


The arithmetic instructions include
Addition
Subtraction
Multiplication
Division
Data Formats
Unsigned binary bytes

Signed binary bytes


Unsigned binary words
Signed binary words
Unpacked decimal bytes
Packed decimal bytes
ASCII numbers

02/21/15

K.Rajalakshmi,JIIT,Noida

Microprocessor Application Engineering

Instruction set

CI 052

Arithmetic Instruction
Addition
ADD

Add byte or word

ADC

Add byte or word with carry

INC

Increment byte or word by 1

AAA

ASCII adjust for addition

DAA

Decimal adjust for addition


Subtraction

02/21/15

SUB

Subtract byte or word

SBB

Subtract byte or word with borrow

DEC

Decrement byte or word by 1

NEG

Negate byte or word

AAS

ASCII adjust for subtraction

DAS

Decimal adjust for subtraction


K.Rajalakshmi,JIIT,Noida

Microprocessor Application Engineering

Instruction set

CI 052

Multiplication
MUL

Multiply byte or word unsigned

IMUL

Integer multiply byte or word

AAM

ASCII adjust for multiply


Division

02/21/15

DIV

Divide byte or word unsigned

IDIV

Integer divide byte or word

AAD

ASCII adjust for division

CBW

Convert byte or word

CWD

Convert word to double word

K.Rajalakshmi,JIIT,Noida

Microprocessor Application Engineering

Instruction set

CI 052

Addition Instruction
Mnemonic

Meaning

Format

Operation

Flag
affected

ADD

Addition

ADD D,S

(S) + (D) (D)


Carry (CF)

OF,SF,ZF,
AF,PF,CF

ADC

Add with carry

ADC D,S

(S) + (D) + (CF) (D)


Carry (CF)

OF,SF,ZF,
AF,PF,CF

INC

Increment by 1

INC D

(D) + 1 (D)

OF,SF,ZF,
AF,PF

AAA

ASCII adjust for


addition

AAA

OF,SF,ZF,
AF,PF,CF,
undefined

DAA

Decimal adjust
for addition

DAA

OF,SF,ZF,
AF,PF,CF,
undefined

02/21/15

K.Rajalakshmi,JIIT,Noida

Microprocessor Application Engineering

Instruction set

Allowed Operands for ADD


and ADC instructions

CI 052

Allowed operand for


INC instruction

Destination

Source

Destination

Register

Register

Reg 16

Register

Memory

Memory

Register

Register

Immediate

Memory

Immediate

Reg 8
Memory

Accumulator Immediate

02/21/15

K.Rajalakshmi,JIIT,Noida

Microprocessor Application Engineering

Instruction set

CI 052

EXAMPLE (1):
Assume that the AX and BX registers contain 110016 and
0ABC16, respectively. What is the result of executing the
instruction ADD AX, BX?
Solution:
(BX)+(AX) = 0ABC16 + 110016
=1BBC16
The sum ends up in destination register AX. That is
(AX) = 1BBC16

02/21/15

K.Rajalakshmi,JIIT,Noida

Microprocessor Application Engineering

02/21/15

Instruction set

K.Rajalakshmi,JIIT,Noida

CI 052

Microprocessor Application Engineering

02/21/15

Instruction set

K.Rajalakshmi,JIIT,Noida

CI 052

Microprocessor Application Engineering

Instruction set

CI 052

EXAMPLE(2):
The original contents of AX, BL, word-size memory location
SUM, and carry flag (CF) are 123416, AB16, 00CD16, and 016,
respectively. Describe the results of executing the following
sequence of instruction?
ADD AX, [SUM]
ADC BL, 05H
INC [SUM]
Solution:
(AX) (AX) + (SUM)

= 123416 + 00CD16 =130116

(BL) (BL) + imm8+(CF) = AB16 + 516+016 = B016


(SUM) (SUM)+ 116
02/21/15

= 00CD16 + 116

K.Rajalakshmi,JIIT,Noida

= 00CE16
10

Microprocessor Application Engineering

Instruction set

CI 052

EXAMPLE (3):
What is the result of executing the following instruction sequence?
ADD AL, BL
AAA
Assuming that AL contains 3216 (ASCII code for 2) and BL contains 3416
(ASCII code 4), and that AH has been cleared.
Solution:
(AL) (AL)+(BL)= 3216 + 3416=6616
The result after the AAA instruction is
(AL) = 0616
(AH) = 0016
with both AF and CF remain cleared
02/21/15

K.Rajalakshmi,JIIT,Noida

11

Microprocessor Application Engineering

Instruction set

CI 052

EXAMPLE (4):
Perform a 32-bit binary add operation on the contents of the
processors register.
Solution:
(DX,CX) (DX,CX)+(BX,AX)
(DX,CX) = FEDCBA9816
(BX,AX) = 0123456716
MOV DX, 0FEDCH
MOV CX, 0BA98H
MOV BX, 01234H
MOV AX, 04567H
ADD CX, AX
ADC DX, BX
02/21/15

; Add with carry


K.Rajalakshmi,JIIT,Noida

12

Microprocessor Application Engineering

02/21/15

Instruction set

K.Rajalakshmi,JIIT,Noida

CI 052

13

Microprocessor Application Engineering

02/21/15

Instruction set

K.Rajalakshmi,JIIT,Noida

CI 052

14

Microprocessor Application Engineering

Instruction set

CI 052

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.


02/21/15

K.Rajalakshmi,JIIT,Noida

15

Microprocessor Application Engineering

Instruction set

CI 052

EXAMPLE

Assuming that the register BX contains 003A 16, what is the


result of executing the following instruction?
NEG BX
Solution:
(BX)

= 000016-(BX)
=000016+2complement of 003A16
= 000016+FFC616
= FFC616

Since no carry is generated in this add operation, the carry flag


is complemented to give
(CF) = 1

02/21/15

K.Rajalakshmi,JIIT,Noida

16

Microprocessor Application Engineering

Instruction set

CI 052

EXAMPLE
Perform a 32-bit binary subtraction for variable X and Y.
Solution:
MOV SI, 200H ; Initialize pointer for X
MOV DI, 100H ; Initialize pointer for Y
MOV AX, [SI] ; Subtract LS words
SUB AX, [DI]
MOV [SI],AX ; Save the LS word of result
MOV AX, [SI]+2 ; Subtract MS words
SBB AX, [DI]+2
MOV [SI]+2, AX ; Save the MS word of result

02/21/15

K.Rajalakshmi,JIIT,Noida

17

Microprocessor Application Engineering

02/21/15

Instruction set

K.Rajalakshmi,JIIT,Noida

CI 052

18

Microprocessor Application Engineering

02/21/15

Instruction set

K.Rajalakshmi,JIIT,Noida

CI 052

19

Microprocessor Application Engineering

Instruction set

CI 052

EXAMPLE
The 2s-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 2s complement) = 111111112 = FF16
(CL) = -2 (as 2s complement) = 111111102 = FE16
Executing the MUL instruction gives
(AX)

= 111111112x111111102
=11111101000000102

=FD0216

Executing the IMUL instruction gives


(AX) = -116 x -216 = 216 = 000216
02/21/15

K.Rajalakshmi,JIIT,Noida

20

Microprocessor Application Engineering

Instruction set

CI 052

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
02/21/15

K.Rajalakshmi,JIIT,Noida

21

Microprocessor Application Engineering

Instruction set

CI 052

BCD and ASCII Arithmetic


BCD Arithmetic :
Addition

: DAA

Subtraction

: DAS

Conventional Hexadecimal Arithmetic BCD Addition [DAA ]


1234 h
1234 h

02/21/15

3099 h

3099 h

------

------

42CD h

4333 h

-------

------K.Rajalakshmi,JIIT,Noida

22

Microprocessor Application Engineering

Instruction set

CI 052

DAA : Decimal Adjustment after Addition

DAS : Decimal Adjustment after Subtraction

DAA instruction functions only with AL register

instruction functions only with AL register

This addition must occur eight bits at a time

This addition must occur eight bits at a time

DAA instruction must come only after Addition


instruction.

DAS instruction must come only after


subtraction instruction

Example program for 16-bit BCD addition


MOV DX,1234 H

Example program for 16-bit BCD


subtraction
MOV DX,1234 H

MOV BX,3099H

MOV BX,3099H

MOV AL,BL

MOV AL,BL

ADD AL,DL

ADD AL,DL

DAA

DAA

MOV CL,AL

MOV CL,AL

MOV AL,BH

MOV AL,BH

ADC AL,DH

ADC AL,DH

DAA

DAA

MOV CH,AL
02/21/15

MOV CH,AL
K.Rajalakshmi,JIIT,Noida

23

Microprocessor Application Engineering

Instruction set

CI 052

ASCII Arithmetic
The ASCII arithmetic instructions functions with ASCII-coded numbers
The numbers range in value from 30-39 h for the numbers 0-9.

02/21/15

K.Rajalakshmi,JIIT,Noida

24

Microprocessor Application Engineering

Instruction set

AAA

CI 052

AAD

AAM

ASCII adjustment after addition

ASCII adjustment after Division

ASCII adjustment after


Multiplication

Appears after addition instruction.

Appears before division instruction

Appears after multiplication

ADD instruction
31h + 39h = 6Ah

AX contain a two digit unpacked BCD


number
Adjust AX with ADD.
Divide AX with an unpacked BCD number
AL will have Quotient
AH will have Reminder

MUL instruction
05H * 05H = 0019H

AAA instruction
1 + 9 = 10 =01 00h

DIV instruction
72 / 9 => AL=8 ; AH =0

AAM Instruction
5 * 5 = 02 05H

To get ASCII code


0100h+3030h = 3130h

AAD instruction
0702H is loaded into AX
Adjust by AAD instruction
AX will have 0048
0048 is binary equivalent of 72 decimal

To get ASCII code


0205h + 3030h = 3235h

Example
MOV AX, 31H
ADD AL,39H
AAA
ADD AX,3030H

Example
MOV BL, 9
MOV AX,0702H
AAD
DIV BL

Example
MOV AL,5
MOV CL,5
MUL CL
AAM

02/21/15

K.Rajalakshmi,JIIT,Noida

25

You might also like