February 24, 2012
Write an assembly language program to convert given hexadecimal number into equivalent BCD number.
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: In this program we have to convert given hex number into its equivalent BCD number. If a hex number is FF then its equivalent BCD number will be 0255.
Algorithm:
- Initialize HL pair as memory pointer
- Get number into any register as C
- Perform repeated addition for C number of times.
- Adjust for BCD at each step
- Store the BCD number at memory location.
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
H,2050 H
|
Memory pointer Initialization
|
2003
|
MVI
|
D,00 H
|
For MSD
|
2005
|
XRA
|
A
|
Clear the accumulator
|
2006
|
MOV
|
C,M
|
Get hex data into A
|
2007
|
ADI
|
01
|
Count no. one by one
|
2009
|
DAA
|
Adjust for BCD
| |
200A
|
JNC
|
200E
|
Jump for no carry
|
200D
|
INR
|
D
|
Increment D
|
200E
|
DCR
|
C
|
Decrement counter C
|
200F
|
JNZ
|
2007
|
Jump for no zero
|
2012
|
STA
|
2051 H
|
Store LSD
|
2015
|
MOV
|
A,D
| |
2016
|
STA
|
2052 H
|
Store MSD
|
2019
|
RST
|
5
|
Set Break-point
|
201A
|
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 the 8 bit data in specified register.
MOV: This instruction is used to copy the content from source register to destination register.
JNC: Jump if not carry at specified memory address.
JNZ: Jump if value of specified register is not zero.
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
INR: It will increment the content of specified register by one.
ADI: This instruction is used to add the 8-bit data to the content of accumulator and store output in accumulator.
XRA: The contents of the register are logically EX-OR ed with the contents of accumulator.
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-FF H
Output:
2051-55 (LSB)
2052-02 (MSB)
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:FF)
- 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 (M2051) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
information on site is very helpful. But it will be more helpful if u add some project and related information to it like how any project is made, how it will work, coding etc....
ReplyDeleteotherwise it was excellent.
Thanks for your valuable comment... I am trying to do that but it takes some time.....so after some gap you can also find details regarding project
ReplyDeletevery very useful for me ,as a beginner..,,,,,,,,thank u :)
ReplyDelete