You are on page 1of 23

MICROPROCESSORS

AND
MICROCONTROLLERS

MPMC LAB ASSIGNMENT-2

BLOCK MOVE & ARTHEMATIC OPERATIONS

Name: G Balaaditya Kumar


Roll Number: 108120040
Branch: ECE
Section: B
Date: 12-02-2022
1. Briefly explain about arithmetic instructions in 8086 with examples. Where
will be the remainder of the result stored for DIV instruction?

ANSWER:
Arithmetic Instructions in 8086:

a. ADD

Syntax: ADD operand1 , operand2

Operand1  operand1 + operamd2

The values of both the operands are added and the final value is stored in operand1.

If there is extra carry, it is then stored in the Carry flag(CF).

b. SUB

Syntax: SUB operand1 , operand2

Operand1  operand1 - operamd2

The value of operand2 is subtracted from operand1 and the final value is stored in operand1.

c. MUL

Syntax: MUL operand

MUL depends on 3 accumulations in 8086.

For 8-bit

AL for 8-bits

For 16-bit

AX for other 16-bits.

For 32-bit

AX and DX are used.

Accumulators used for different operation depends size of operand

AX  AL * operand (8-bit operand)


DX*AX  AX*operand(16-bit operand)

(AX stores lower bits and DX stores higher bits)

If we must multiply 8 and 16-bit numbers. Then we have to convert 8-bit number into 16-bit
number.

d. IMUL

Synatx: IMUL operand

The only difference form MUL is used for unsigned numbers but IMUL is used for signed
numbers multiplication.

e. DIV

Syntax: DIV operand

The operand in this instruction is divisor. String of division result again depends on size.

For8-bit

AH*AL  AX / operand

AL stores quotient & AH stores remainder.

For 16-bit

DX*AX  (DX*AX)/operand

AX stores quotient and DX stores remainder.

If we must divide 8 and 16-bit numbers. Then we have to convert 8-bit number into 16-bit
number.

f. IDIV

Syntax: IDIV operand

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.

Syntax: MOV destination , source

The value in source is stored into the destination.

Example:

MOV AX , 1025H

The value 1025H is stord in AX.

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

MOVSB – Movement of a byte.

MOVSW _ Movement of a word.

MOVSD_ Movement of a double word.

Syntax: MOVS destination , Source.

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

The Direction flag is set as 0.

4. STD
It is used to set Direction flag. Command STD implies data goes backward. SI/DI
decrease automatically.

Syntax: STD

The direction flag will be set as 1.

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

The next operation will be repeated.

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.

3. Auxiliary Carry Flag(AF)

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)

If the result is zero, then the flag is set i.e, made 1.

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

Value of 0A1D1H in decimal is 41425

When we add both the values the result is (19CB1)H and its decimal value is
105649.

The flags CF PF SF IF are set i.e, made as 1.

The reason is

CF because we have a carry when we add these both numbers.

PF because there are even number of set bits in the result.

IF as the programmer wants interrupt to be set.

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

a. Move a block of data (16-bit number) from source location (DS:SI)


to destination location (ES:DI).

b. Perform all arithmetic operations of two 16-bit numbers (signed


and unsigned numbers) and check the flag status.

1. Unsigned addition to show CF=0

2. Unsigned addition to show CF=1

3. Signed addition to show SF=1

4. Unsigned subtraction to show ZF=1

5. Signed subtraction to show Borrow flag=1

6. Unsigned multiplication (operand 8 bit)

7. Signed multiplication (operand 16 bit)

8. Unsigned division (operand 8 bit)

9. Signed division (operand 16 bit)


Aim:
As given in the question:

a. Move a block of data (16-bit number) from source location (DS:SI) to


destination location (ES:DI)
b. Perform all arithmetic operations of two 16-bit numbers (signed and
unsigned numbers) and check the flag status.

Software required:
Emulator 8086

Program Code:
a. BLOCK MOVE

Screen shot of the code:


Table-1:
Label CS:IP Opcode Operand Comment
DX , 1340H Value of 1340H is stored
Immediate 0100:0000 MOV in DX.
DS , DX Value at DX is copied to
Register 0100:0003 MOV DS value.
SI , 1221H Value of 1221H is stored
Immediate 0100:0005 MOV in SI
[SI] , 2342H Value of 2342H is stored
Direct 0100:0008 MOV in memory at address
1221H
[SI-2] , 3692H Value of 3692H is stored
Direct 0100:000C MOV in memory at address
121FH
[SI-4] , 4971H Value of 4971H is stored
Direct 0100:0011 MOV in memory at address
121DH
[SI-6] , 5163H Value of 5163H is stored
Direct 0100:0016 MOV in memory at address
121BH
[SI-8] , 8569H Value of 8569H is stored
Direct 0100:001B MOV in memory at address
1219H
DX , 4598H Value of 4598H is stored
Immediate 0100:0020 MOV in DX.
ES , DX Value of DX is copied in to
Register 0100:0023 MOV ES.
DI , 7458H Value of 7458H is stored
Immediate 0100:0025 MOV in DI.
- The Direction flag is set as
Implied 0100:0028 STD 1.
CX , 5 Value of 0005H is stored
Immediate 0100:0029 MOV in CX.
- The next instruction is
Implied 0100:002C REP repeated for CX times.
- The values at [DS:SI] is
String 0100:002D MOVSW copied i.e transferred to
Addressing [ES:DI]
Result:
Screenshot of results
Memory at Source:

Memory at Destination:

Tabulate the obtained results as shown below.

Table-2:

Before Execution After Execution


Register H L H L
DX xx xx 13 40
DS 01 00 13 40
SI xx xx 12 21
DX 13 40 45 98
ES 01 00 45 98
DI xx xx 74 56
CX xx xx 00 05
Table-3:

Source location Destination location


DS:SI H L ES:DI H L
1340:1221 23 42 4598:7458 23 42
1340:121F 36 92 4598:7456 36 92
1340:121D 49 71 4598:7454 49 71
1340:121B 51 63 4598:7452 51 63
1340:1219 85 69 4598:7450 85 69

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.

0100:000B idiv BX Value of AX =


0009H
(DX*AX)/BX
And modulus of
the remainder is
31D6H and is
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.

You might also like