January 11, 2012
Write an assembly language program t0 decimal addition for two 8 bit numbers, output more than 8 bit number using memory location. (Carry)
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to add two 8 bit numbers which are stored at different memory location and output should be more than 8 bit number and output should be store at another memory location. Output will be in decimal.
Algorithm:
- Initialize memory pointer
- Move First Number into Accumulator
- Get second Number using memory location
- Now add first number and second number
- Convert hexadecimal value into decimal
- Check for the carry
- Store the carry at memory location
- Store output at another memory location
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
H,2050 H
|
Load first number at 2050 H
|
2003
|
MVI
|
C,00 H
|
Initialize C for the carry
|
2005
|
MOV
|
A,M
|
Move the first number into A
|
2006
|
INX
|
H
|
Get Second number
|
2007
|
ADD
|
M
|
Add first number and Second
|
2008
|
DAA
|
Decimal adjust accumulator
| |
2009
|
JNC
|
200D
|
Check Carry
|
200C
|
INR
|
C
|
Increment C if there is carry
|
200D
|
STA
|
2052 H
|
Store output at 2052
|
2010
|
MOV
|
A,C
|
Store Carry in A
|
2011
|
STA
|
2053
|
Store carry at 2053
|
2014
|
RST
|
5
|
Set Break-point
|
2015
|
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.
MVI: This instruction is used to store 8 bit data in specified register.
MOV: This instruction is used to copy the content from source register to destination register.
INX: This instruction is used to increment the content of register pair by one.
ADD: This instruction is used to add the content of specified register to the content of accumulator and store output in accumulator.
DAA: If the value of low order four bits in the accumulator is greater then 9 or if auxiliary carry flag is set, the instruction adds 6 to the low order four bits. If the value of high order four bits in the accumulator is greater then 9 or if auxiliary carry flag is set, the instruction adds 6 to the high order four bits
JNC: Jump if not carry at specified memory address.
INR: It will increment the content of specified register by one.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input: 2050-45
2051-55
Output: 2052-00 H
2053-01 H (carry)
Input: 2050-45
2051-55
Output: 2052-00 H
2053-01 H (carry)
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 (M2050)
- Press ENTER and Provide your Input at location (2050: 45)
- Press ENTER and Provide your Second Input (2051 :55)
- 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 (M2052) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
ty
ReplyDeleteGenius bro thanks a lot
ReplyDelete