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 from Binary Code to Gray Code.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to convert binary code to grey code. Suppose a number stored at 2050 H and we have to store converted grey code at 2051 H.
Algorithm:
  • Load data at input location
  • Store that number in register B
  • Rotate left with carry
  • Store content of A into C
  • Store content of B into A
  • Rotate accumulator left
  • Store content of C into A
  • Rotate right with carry
  • Store output at memory location
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LXI
H,2050 H
Get data at this location
2003
MOV
A,M
Store data in accumulator
2004
MOV
B,A
Store data in register B
2005
RLC

Rotate left with carry
2006
MOV
C,A
Store accumulator in C
2007
MOV
A,B
Now get B into A
2008
RAL

Rotate accumulator left
2009
MOV
A,C
Get the C into A
200A
RRC

Rotate right with carry
200B
STA
2051 H
Store the result
200E
RST
5
Set Break-point(optional)
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.
RLC: Each binary bit of the accumulator is rotated left by one. Bit D7 is placed in the position of D0 as well as carry flag.
RAL: Each binary bit of accumulator is rotated left by one position through the carry flag. Bit D7 is placed in the carry flag and the carry flag is placed in LSB bit position D7.
RRC: Each binary bit of the accumulator is rotated right by one. Bit D0 is placed in the position of D7 as well as carry flag
MOV: This instruction is used to copy the content from source register to destination register.
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 H-58 (Binary)           
Output: 2051 H- 74 (Grey)             
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:58)
  • 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.

No comments:

Post a Comment