Professional Documents
Culture Documents
AND
MICROCONTROLLERS
ANSWER:
Arithmetic Instructions in 8086:
a. ADD
The values of both the operands are added and the final value is stored in operand1.
b. SUB
The value of operand2 is subtracted from operand1 and the final value is stored in operand1.
c. MUL
For 8-bit
AL for 8-bits
For 16-bit
For 32-bit
If we must multiply 8 and 16-bit numbers. Then we have to convert 8-bit number into 16-bit
number.
d. IMUL
The only difference form MUL is used for unsigned numbers but IMUL is used for signed
numbers multiplication.
e. DIV
The operand in this instruction is divisor. String of division result again depends on size.
For8-bit
AH*AL AX / operand
For 16-bit
DX*AX (DX*AX)/operand
If we must divide 8 and 16-bit numbers. Then we have to convert 8-bit number into 16-bit
number.
f. IDIV
The only difference form MUL is used for unsigned numbers but IMUL is used for signed
numbers multiplication.
Where will be the remainder of the result stored for DIV instruction?
The remainder of the result will be stored in DX for 16-bit and AH for 8-bit.
2. Write about the following instructions with examples. MOV, MOVS, CLD,
STD, REP.
ANSWER:
1. MOV
This is one of the most important commands in 8086 as it transfers data from one
location to other location.
Example:
MOV AX , 1025H
2. MOVS
It is used to copy data item (byte, word) from source to destination string. Source
& destination string are pointed by DS:SI & ES:DI respectively. It has 3 variants
Example:
MOVSB
3. CLD
It is used to clear direction flag. Command CLD implies data goes forward in SI/DI.
That is SI/DI Increase automatically.
Syntax: CLD
4. STD
It is used to set Direction flag. Command STD implies data goes backward. SI/DI
decrease automatically.
Syntax: STD
5. REP
It stands for repeat. Instruction is repeated CX number of times. After each
execution, SI/DI registers are incremented/decremented according to the
direction flag.
Syntax: REP
3. How many valid flag bits are there in 8086? Explain about each flag
bit in detail.
ANSWER
There are 9 flag bits in 8086. Out of those 9 flag bits, 3 are Control flag bits and
the remaining 6 flag bits are Status Flag bits.
Status Flags:
1. Carry Flag(CF)
The carry flag is set i.e 1 if there is carry/borrow from the MSB , otherwise it is
reset i.e cleared.
2. Priority Flag(PF)
8086 microprocessor follows even priority. When result has even number of 1`s
and parity flag is set.
While doing arithmetic operations, if there is carry from lower nibble to higher
nibble, then auxiliary carry flag is et i.e, made as 1.
4. Zero Flag(ZF)
5. Sign Flag(SF)
Sign flag is set i.e made 1, when the result is negative while doing signed
operations.
6. Overflow Flag(OF)
If the result of any operation goes out of range, then overflow flag is set i.e, made
as 1.
Control Flags:
User controls these, as per their requirements:
1. Trap Flag(TF)
If we set the trap flag i.e ,made as 1. Microprocessor executes each program with
single steps.
2. Interrupt Flag(IF)
If programmer wants to access the interrupts , IF is set as 1.
3. Direct Flag(DF)
If DF is set i.e, made 1 , SI/DI constantly decrease automatically.
If DF is reset i.e made 0, SI/DI constantly increase automatically.
4. Consider the following instructions. Which flag bits are set upon
execution of the code? Why?
MOV AX,0FAE0H
MOV BX,0A1D1H
ADD AX,BX
ANSWER
Value of 0FAE0H in decimal is 64224
When we add both the values the result is (19CB1)H and its decimal value is
105649.
The reason is
SF because the value we obtained is 16 bit. The result can be stored only if it is
signed addition, therefore SF is set as 1.
5. Write assembly language instructions to
Software required:
Emulator 8086
Program Code:
a. BLOCK MOVE
Memory at Destination:
Table-2:
b. ARITHMETIC OPERATIONS
Screen shot of the code:
Unsigned Addition(CF=0)
Unsigned Addition(CF=1)
Signed Addition(SF=1)
Unsigned Subtraction(ZF=1)
Signed Subtraction(CF=1)
Unsigned Multiplication
Signed Multiplication
Unsigned Division
Signed Division
Table-1:
Label CS:IP Opcode Operand Comment
Unsigned 0100:0003 mov AX , 4567H 04567H value
moves into AX.
Addition
(CF=0) 0100:0006 mov BX , 1239H 1239H value is
moved into BX
0100:0008 add BX , AX
Value of sum is
stored in BX.
Unsigned 0100:0003 mov AX , 7654H 7654H value
moves into AX.
Addition
(CF=1) 0F111H value is
0100:0006 mov CX , 0F111H moved into CX
Value of sum is
6765 and stored in
0100:0008 add CX , AX CX.
CF = 1
Unsigned 0100:0003 mov AX , 0F125H 0F125H value
moves into AX.
Addition
(CF=1) 0FDD3H value is
0100:0006 mov BX , 0FDD3H moved into BX
Value of sum is
EEF8 and stored in
0100:0008 add BX , AX BX.
SF = 1
Unsigned 0100:0003 mov AX , 9956H 9956 value moves
into AX.
Subtraction
(ZF=1) 9956H value is
0100:0006 mov BX , 9956H moved into BX
Value of result is
0000Hand stored
in BX.
0100:0008 sub BX , AX ZF = 1
signed 0100:0003 mov AX , 0FFDFH 0FFDFH value
moves into AX.
Subtraction
(CF=1) 0FDEFH value is
0100:0006 mov BX , 0FDEFH moved into BX
Value of result is
FE10H and stored
in BX.
0100:0008 sub BX , AX CF = 1
Unsigned 0100:0003 mov AX , 0095H 0095H value
moves into AX.
Multiplication
0021H value is
(8-bit) 0100:0006 mov DX , 0021H moved into DX
Value of result is
1315Hand stored
in AX.
0100:0008 mul DX
Signed 0100:0003 mov AX , 0F23H 0F23H value
moves into AX.
Multiplication
(16-bit) 2456H value is
0100:0006 mov CX , 2456H moved into CX
Value of result is
stored in AX and
as well as DX.
0100:0008 imul CX Since the resultant
is 32bit number.
Unsigned 0100:0003 mov AX , 2456H 2456H value
moves into AX.
Division
0022H value is
(8-bit) 0100:0006 mov CX , 0022H moved into CX
Value of result is
0111H and stored
in AX and the
0100:0008 div CX remainder is
stored in Dx and it
is 0014H.
Signed 0100:0003 mov BX , 0CB25H 0F23H value
moves into AX.
Division
(16-bit) 2456H value is
0100:0006 mov AX , 1023H moved into CX
Value of 0002H is
0100:0008 mov DX , 0002H stored in DX.
Result:
Screenshot of results
Unsigned Addition(CF=0)
Unsigned Addition(CF=1)
Signed Addition(SF=1)
Unsigned Subtraction(ZF=1)
Signed Subtraction(CF=1)
Unsigned Multiplication
Signed Multiplication
Unsigned Division
Signed Division
Table-2:
Before After Flag
Execution Execution
LABEL REGISTER H L H L CF ZF SF OF PF AF IF DF
Unsigned AX xx xx 45 67 0 0 0 0 1 1 1 0
Addition
(CF=0) BX xx xx 12 39
BX(sum) 12 39 57 A0
Unsigned AX xx xx 76 54 1 0 0 0 1 0 1 0
Addition
(CF=1) CX xx xx F1 11
CX(sum) F1 11 67 65
Signed AX xx xx F1 25 1 0 1 0 0 0 1 0
Addition
(SF=1) BX xx xx FD D3
BX(sum) FD D3 EE F8
Unsigned AX xx xx 99 56 0 1 0 0 1 0 1 0
Subtraction
(ZF=1) BX xx xx 99 56
BX(sub) 99 56 00 00
Signed AX xx xx FF DF 1 0 1 0 0 0 1 0
Subtraction
(CF=1) BX xx xx FD EF
BX(sub) FD EF FE 10
Unsigned AX xx xx 00 95 0 0 0 0 0 0 1 0
Multiplication
DX xx xx 00 21
AX(mul) 00 95 13 35
DX 00 21 00 00
Signed AX xx xx F2 3F 1 0 0 1 0 0 1 0
Multiplication
CX xx xx 24 56
AX(mul) F2 3F 3D 2A
DX 00 00 FE 0C
Unsigned AX xx xx 24 56 0 0 0 0 0 0 1 0
Division
CX xx xx 00 22
AX(div) 24 56 01 11
DX 00 00 00 14
Signed AX xx xx 10 23 0 0 0 0 0 0 1 0
Division
BX xx xx 35 25
DX xx xx 00 02
AX(div) 35 25 00 09
DX 00 02 31 D6
Result:
The Block Move and Arithmetic Operations of Intel 8086 Microprocessor are
studied and verified using emu8086 Software.