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 2-digit BCD to Binary Conversion.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to convert 2-digit BCD into Binary Number. For example 67= 6 * 0A (10) +7= 3CH+7= 43 H. We have to store number at 2200 H and store output at 2300 H.
Algorithm:
  • Get the number
  • Mask the upper nibble and store as BCD number
  • Get number again
  • Mask lower nibble exchange nibble position of result and store it as BCD2
  • Multiply BCD2 by 10
  • Add BCD1
  • Store output at memory location
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LDA
2200 H
Get BCD digit
2003
MOV
B,A
Store number in B
2004
ANI
0F
Mask MSB four bits
2006
MOV
C,A
Save unpacked BCD1 in C
2007
MOV
A,B
Get BCD again
2008
ANI
F0H
Make LSB BCD digit zero
200A
RRC
Convert MSB into unpacked BCD2
200B
RRC
200C
RRC
200D
RRC
200E
MOV
B,A
Save unpacked BCD2 in register
200F
XRA
A
Clear Accumulator
2010
MVI
D,0AH
Set D as multiplier of 10
2012
ADD
D
Add D with Accumulator
2013
DCR
B
Decrement B
2014
JNZ
2012
Jump multiplication is no complete
2017
ADD
C
Add BCD1 with accumulator
2018
STA
2300 H
Store the result
201B
RST
5
Set Breakpoint(optional)
201C
END
End the program

Used Instruction: 
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
RRC: Each binary bit of the accumulator is rotated right by one. Bit D7 is placed in the position of B0 as well as carry flag.
ANI: This instruction logically ANDs the 8-bit data given in the instruction with the contents of accumulator and stores the result in the accumulator. 
MOV: This instruction is used to copy the content from source register to destination register.
JNZ: Jump if counter is not zero at target address.
XRA: It perform Ex-or operations with accumulator 
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 breakpoint for the execution.
END: This instruction is used to execute the program.
 
Result:  
Input: 2200 H-67
Output: 2300 H-43 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 (M2200)
  • Press ENTER and Provide your Input at location (2200:67)
  • 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.

No comments:

Post a Comment