Unit 2
Unit 2
PROGRAMMING – INTEGER
INSTRUCTIONS AND
COMPUTATIONS
8088/8086 MICROPROCESSOR
PROGRAMMING – INTEGER
INSTRUCTIONS AND COMPUTATIONS
MOV [SUM], AX
Data-Transfer Instructions (cont.)
The MOVE Instruction
Note that the MOV instruction cannot transfer
data directly between external memory
Data-Transfer Instructions (cont.)
The MOVE Instruction
MOV DX, CS
Data-Transfer Instructions (cont.)
The MOVE Instruction
MOV DX, CS
Data-Transfer Instructions (cont.)
EXAMPLE:
What is the effect of executing the instruction?
MOV CX, [SOURCE_MEM],
where SOURCE_MEM equal to 2016 is a memory location
offset relative to the current data segment starting at
1A00016
Solution:
((DS)0+2016) (CL)
((DS)0+2016+116) (CH)
Therefore CL is loaded with the contents held at memory address
1A00016 + 2016 = 1A02016
and CH is loaded with the contents of memory address
1A00016 + 2016 +116 = 1A02116
Data-Transfer Instructions (cont.)
The XCHG Instruction
The exchange (XCHG) instruction can be used to
swap data between two general-purpose
registers or between a general purpose register
and a storage location in memory
Allowed operands
for INC instruction
Allowed operands for ADD and
ADC instructions
Arithmetic Instructions (cont.)
EXAMPLE:
Assume that the AX and BX registers contain
110016 and 0ABC16, respectively. What is the
result of executing the instruction ADD AX, BX?
Solution:
(AX) = 1BBC16
Arithmetic Instructions (cont.)
Addition Instructions: ADD, ADC, INC, AAA,
DAA
ADD AX, BX
Arithmetic Instructions (cont.)
Addition Instructions: ADD, ADC, INC, AAA,
DAA
ADD AX, BX
Arithmetic Instructions (cont.)
EXAMPLE:
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 WORD PTR [SUM]
Solution:
(AX) (AX)+(SUM) = 123416 + 00CD16 =130116
(BL) (BL)+imm8+(CF) = AB16 + 516+016 = B016
(SUM) (SUM)+ 116 = 00CD16 + 116 = 00CE16
Arithmetic Instructions (cont.)
EXAMPLE:
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
Arithmetic Instructions (cont.)
EXAMPLE:
Perform a 32-bit binary add operation on the contents of
the processor’s 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 ; Add with carry
Arithmetic Instructions (cont.)
Subtraction Instructions: SUB, SBB, DEC, AAS,
DAS, and NEG
Arithmetic Instructions (cont.)
Subtraction Instructions: SUB, SBB, DEC, AAS,
DAS, and NEG
SHL AX, 1
SHR AX, CL
(CL)=2
SAR AX, CL
(CL)=2
Shift Instructions (cont.)
EXAMPLE:
Assume that CL contains 0216 and AX contains
091A16.
Determine the new contents of AX and the carry
flag after the instruction SAR AX, CL is executed
Solution:
(AX)=00000010010001102=024616
ROL AX, 1
ROR AX, CL
(CL)=4
Rotate Instructions (cont.)
Rotate instructions: ROL, ROR, RCL, RCR
For RCL, RCR, the bits are rotate through the carry flag
Rotate Instructions (cont.)
EXAMPLE:
What is the result in BX and CF after execution of
the following instructions?
RCR BX, CL
Assume that, prior to execution of the
instruction, (CL)=0416, (BX)=123416, and (CF)=0
Solution:
The original contents of BX are
(BX) = 00010010001101002 = 123416
Execution of the RCR command causes a 4-bit
rotate right through carry to take place on the data
in BX, the results are
(BX) = 10000001001000112 = 812316
(CF) = 02
Rotate Instructions (cont.)
EXAMPLE:
Disassembly and addition of 2 hexadecimal digits
stored as a byte in memory.
Solution:
MOV AL, [HEX_DIGITS]
MOV BL, AL
MOV CL, 04H
ROR BL, CL
AND AL, 0FH
AND BL, 0FH
ADD AL, BL