April 02, 2012
Write an assembly language program divide the 16-bit number by 8-bit number.
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to divide a 16-bit number by 8 bit number. Let assume that 16 bit number are stored at 2201 and 2202 and 8-bit number is stored at 2203 H. After division store the quotient at 2300 and remainder at 2302 and 2303 H.
Algorithm:
- Get the dividend and divisor
- Initialize quotient as 0
- Dividend as dividend-divisor
- Quotient as quotient+1
- Check for Is dividend
- If yes then remainder is equal to dividend
- If no then repeat the process
- Store quotient and remainder
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LHLD
|
2201 H
|
Load dividend in H-L register pair
|
2003
|
LDA
|
2203 H
|
Load divisor in accumulator
|
2006
|
MOV
|
C,A
|
Move the divisor into C
|
2007
|
LXI
|
D,0000 H
|
Initialize quotient=0 in the D-E rp
|
200A
|
MOV
|
A,L
|
Move LSB of dividend into Accumulator
|
200B
|
SUB
|
C
|
Subtract divisor form accumulator
|
200C
|
MOV
|
L,A
|
Store partial result into Accumulator
|
200D
|
JNC
|
200D
|
If no carry then Jump to
|
2010
|
MOV
|
A,H
|
If carry generated then move MSB in A
|
2011
|
CPI
|
00 H
|
Check if higher byte =0
|
2013
|
JZ
|
A,C
|
Jump at if zero
|
2016
|
DCR
|
H
|
If it not 0 then subtract borrow from H
|
2017
|
INX
|
D
|
Increment the quotient
|
2018
|
JMP
|
Loop back to next subtraction
| |
201B
|
MOV
|
A,L
|
Correct the remainder by adding divisor
|
201C
|
ADD
|
C
| |
201D
|
MOV
|
L,A
| |
201E
|
SHLD
|
2302
|
Store the remainder
|
2021
|
XCHG
|
Exchange the content of H-L to D-E
| |
2022
|
SHLD
|
2300
|
Store the quotient
|
2025
|
RST
|
5
|
Set Breakpoint
|
2026
|
END
|
End the program
|
Used Instruction:
LHLD addr: This instruction copies the contents of memory location given within the instruction into L register and contents of next memory location into the H register.
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
MOV: This instruction is used to copy the content from source register to destination register.
SUB: This instruction is used to subtract the content of memory/register from accumulator and stores output in accumulator.
CPI: This instruction used to compare given data with accumulator.
JZ: Jump if zero at target address.
DCR: This instruction is used decrement the content of specified register by 1.
INX: This instruction is used to increment the content of register pair by one.
JMP: Jump unconditionally at target address.
ADD: This instruction is used to add the content of specified register to the content of accumulator and store output in accumulator.
JNC: Jump if not carry at specified memory address.
XCHG: Exchange the Contents of H with D and L with E.
SHLD: The contents of register L are stored in the memory location specified by the 16-bit address in the operand and the contents of register H are stored in the next memory location.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Data:
Input: 2201-9F H
2202-70 H
2203-0F H
Result: 709F H/0F H=782 H (quotient) and 01 H remainder
Output: 2300-82 H
2301-07 H
2302-01 H (remainder)
2303-00
Procedure to look output
- After press ENTER, You will get first screen
- Press G and Provide Initial address (as 2000)
- Press SHIFT+4,You will get first screen again
- Press M and Provide Input location for Input (M2201)
- Press ENTER and Provide your Input at location (2201: 9F)
- Press ENTER and Provide your Second Input (2202:70) and so on…..
- Press SHIFT+4
- Press G and Provide Initial address (as 2000)
- Press SHIFT+4,You will get first screen again
- Press M and Provide address for output (M2300) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
thanx for alp actually i don't known eng ........give me some tips to improve my spoken skill
ReplyDelete