Running 2 Youtube Channel : The Masti Adda (Fun based ) : The Knowledge Adda (Knowledge based) : Subscribe for Knowledge with Fun....

Write an assembly language program to convert two BCD number to the equivalent HEX number.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: Suppose MSD of the number store at 2050 and LSD at 2051. We have to convert this 8-bit number into hex number. As example 02 is stored at 2050 and 09 at 2051. Your BCD number is 29 and its equivalent Hex number will be at ID and store it at 2052 H.
Algorithm:
  • Initialize HL pair as memory pointer
  • Get MSD of the number
  • Multiply MSD by ten times using repeated addition.
  • Add LSD of the number to the result obtained from the previous step.
  • Store the hex number at memory location.
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LXI
H,2050 H
Memory pointer Initialization
2003
MOV
A,M
Store into Accumulator
2004
ADD
A
MSDX2
2005
MOV
B,A
Store output into B
2006
ADD
A
MSDx4
2007
ADD
A
MSDx8
2008
ADD
B
MSDx10 times
2009
INX
H
Point to LSD
200A
ADD
M
Add to form Hex number
200B
STA
2052 H
Store output at location
200E
RST
5
Set Break-point
200F
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.
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 specified 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.
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-02 (MSD)
2051-09(LSD)
Output:
2052-ID H
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:02)
  • Press ENTER and provide your Input at location (2051:09) 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 (M2052) and press ENTER
  • You will get your desired output.

No comments:

Post a Comment