Write and execute an alp to 8086 Microprocessor to divide a 32 bit unsigned numbers by a 16 bit unsigned number. Store the result in stack segment

1.Division of unsigned numbers

Aim:

To write an assembly language program to perform division of 16-bit unsigned number by 8-bit unsigned number.

Tools:

PC installed with TASM.

Program:

ASSUME CS : CODE, DS : DATA
CODE SEGMENT
MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
DIV OPR2
MOV RESQ, AL
MOV RESR, AH
HLT
CODE ENDS
DATA SEGMENT
OPR1 DW 2C58H
OPR2 DB 56H
RESQ DB ?
RESR DB ?
DATA ENDS
END

List file:

ADDRESS OPCODE OPERATION COMMENTS
0000 B88F4E MOV AX,4E8F INITIALIZATION OF
 DATA SEGMENT
 
0003 8ED8 MOV DS,AX
0005 A10000 MOV AX,[0000] THE VALUE IN [0000] IS MOVED
 TO AX
0008 F6360200 DIV BYTE PTR [0002] THE VALUE IN [0002] IS ADDED
 TO AX
000C A20300 MOV [0003],AX THE VALUE IN AL IS MOVED
 TO [0003]
000F 88260400 MOV [0004],DX THE VALUE IN AH IS MOVED 
TO [0004]
0013 F4 HLT END OF PROGRAM
 

Flow Chart:

Result:

Flags:

Before execution, c=0, s=0, z=0, o=0, p=0, a=0, i=1, d=0.
After execution, c=0, s=0, z=0, o=0, p=0, a=1, i=1, d=0.

Input:

OPR1 = 2C58H (DIVIDEND)
OPR2 = 56H (DIVISOR)

Output:

RESQ = 84H (AL)
RESR = 00H (AH)

 

2. DIVISION OF SIGNED NUMBERS

Aim:

To write an assembly language program to perform division of 16-bit signed number by 8-bit signed number.

Tools:

PC installed with TASM.

Program:

ASSUME CS : CODE, DS : DATA
CODE SEGMENT
MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
IDIV OPR2
MOV RESQ, AL
MOV RESR, AH
HLT
CODE ENDS
DATA SEGMENT
OPR1 DW 26F8H
OPR2 DB 0AAH
RESQ DW ?
RESR DW ?
DATA ENDS
END

List file:

ADDRESS OPCODE OPERATION COMMENTS
0000 B88F4E MOV AX,4E8F INITIALIZATION OF
 DATA SEGMENT
 
0003 8ED8 MOV DS,AX
0005 A10000 MOV AX,[0000] THE VALUE IN [0000] IS MOVED
 TO AX
0008 F63E0200 DIV BYTE PTR [0002] THE VALUE IN [0002] IS ADDED
 TO AX
000C A20300 MOV [0003],AX THE VALUE IN AL IS MOVED
 TO [0003]
000F 88260400 MOV [0004],DX THE VALUE IN AH IS MOVED 
TO [0004]
0013 F4 HLT END OF PROGRAM
 

Flow Chart:

Result:

Case 1:  two positive numbers

Flags:

Before execution, c=0, s=0, z=0, o=0, p=0, a=0, i=1, d=0.
After execution, c=0, s=0, z=0, o=0, p=0, a=1, i=1, d=0.

Input:

OPR1 = 26F8H (DIVIDEND)
OPR2 = 56H (DIVISOR)

Output:

RESQ = 74H (AL)
RESR = 00H (AH)

Case 2: one positive number & one negative number

Flags:

Before execution, c=0, s=0, z=0, o=0, p=0, a=0, i=1, d=0.
After execution, c=0, s=0, z=0, o=0, p=0, a=1, i=1, d=0.

Input:

OPR1 = D908H <- 2’s Complement of (-26F8H)
OPR2 = 56H

Output:

RESQ = 8CH (AL) <- 2’s Complement of (- 74H)
RESR = 00H (AH)

Case 3: one positive number & one negative number

Flags:

Before execution, c=0, s=0, z=0, o=0, p=0, a=0, i=1, d=0.
After execution, c=0, s=0, z=0, o=0, p=0, a=1, i=1, d=0.

Input:

OPR1 =  26F8H
OPR2 = AAH <- 2’s Complement of (-56H)

Output:

RESQ = 8CH (AL)  <- 2’s Complement of (- 74H)
RESR = 00H (AH)

 

3. ASCII division

Aim:

To write an ALP to perform the division of two ASCII numbers.

Tools:

PC installed with TASM.

Program:

ASSUME CS : CODE, DS : DATA
CODE SEGMENT
MOV AX, DATA
MOV DS, AX
MOV AX, DIVIDEND
AAD
MOV CH, DIVISOR
DIV CH
MOV RESQ, AL
MOV RESR, AH
HLT
CODE ENDS
DATA SEGMENT
DIVIDEND DW 0607H
DIVISOR DB 09H
RESQ DB ?
RESR DB ?
DATA ENDS
END

List file

ADDRESS OPCODE OPERATION COMMENTS
0000 B88F4E MOV AX,4E8F INITIALIZATION OF
 DATA SEGMENT
 
0003 8ED8 MOV DS,AX
0005 A10000 MOV AX,[0000] THE VALUE IN [0000] IS MOVED
 TO AX
0008 D50A AAD ASCII ADJUST FOR 
DIVIDION
000A 8A2E0200 MOV CH,[0002] THE VALUE IN [0002] IS
 MOVED TO CH
000E F6F5 DIV CH AX IS DIVIDED BY 
CH
0010 A20300 MOV [0003],AL THE VALUE IN AL IS 
MOVED TO [0003]
0013 88260400 MOV [0002],AH THE VALYE IN AH IS
 MOVED TO [0004]
0017 F4 HLT END OF PROGRAM
 

Flow Chart:

Result:

Flags:

Before execution, c=0, s=0, z=0, o=0, p=0, a=0, i=1, d=0.
After execution, c=0, s=0, z=0, o=0, p=0, a=0, i=1, d=0.

Input:

DIVIDEND = 0607H <- unpacked BCD of 67
DIVISOR = 09H

Output:

RESQ = 07 (AL)
RESR = 04 (AH)

Viva-voce questions:

1. How many address lines are there in 8086 µP?
2. Give the number of flags in 8086 µP?
3. How to divide 16 bit data by 16 bit data using DIV instruction?
4. What is the use of INT 03 instruction?
5. Which other registers can be used with DIV instruction?