February 08, 2012
Write an assembly language program to add two 16 bit numbers, output 16 bit numbers.
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to add two 16 bit numbers. In this case for any 16 bit number, lower byte takes a location and also higher byte take a location, same for the second number and also for output, so we use 6 memory locations for this.
Algorithm:
- Load First number in H-L Pair
- Load second number in B-C Pair
- Add First Number and Second Number
- Store Output
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
H,8050 H
|
Load 16-bit No. in H-L Pair
|
2003
|
LXI
|
B,123A H
|
Load 16-bit No. in B-C Pair
|
2007
|
DAD
|
B
|
Add First Number and 2nd No.
|
2008
|
SHLD
|
2054
|
Store Output
|
200B
|
RST
|
5
|
Set Break-point
|
200C
|
END
|
End the program
|
Used Instruction:
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
DAD rp: This instruction adds the contents of the specified register pair to the contents of the HL register pair.
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 end the program.
Result:
Input:
First Number-8050
2nd Number-123A
Output:
2054-8A
2055-92
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 G and Provide Initial address (as 2000)
- Press SHIFT+4,You will get first screen again
- Press M and Provide address for output (M2054) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment