February 06, 2012
Write an assembly language program to convert from Gray Code to Binary Code.
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to convert Grey code to Binary code. Suppose a number stored at 2050 H and we have to store converted Binary code at 2051 H.
Algorithm:
- Load data at input location
- Store that number in register B
- Set counter as number of bit
- Decrement counter
- Jump if zero at no operation
- Set carry flag
- Complement of carry flag
- Rotate accumulator right through carry
- XOR specified register with accumulator
- Jump unconditionally at decrement counter
- 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
|
MVI
|
C,08
|
Number of Bit
|
2007
|
DCR
|
C
|
Decrement bit by 1
|
2008
|
JZ
|
2012
|
Jump if zero at No operation
|
200B
|
STC
|
Set the carry flag
| |
200C
|
CMC
|
Complement carry
| |
200D
|
RAR
|
Rotate accumulator right
| |
200E
|
XRA
|
B
|
XOR with register
|
200F
|
JMP
|
2007
|
Jump unconditionally to addr.
|
2012
|
NOP
|
No operation
| |
2013
|
STA
|
2051 H
|
Store the result
|
2016
|
RST
|
5
|
Set Break-point(optional)
|
2017
|
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.
DCR: This instruction is used decrement the content of specified register by 1.
JZ: Jump if counter is Zero
STC: This instruction set carry flag equal to 1
CMC: This instruction complements the carry flag.
RAR: This instruction moves the content of the accumulator right by one position through the carry. Bit D7 placed in CY and CY is placed in D7.
XRA: This instruction logically XORs the contents of the specified register with content of accumulator and stores the result in the accumulator.
MOV: This instruction is used to copy the content from source register to destination register.
JMP: This instruction jump unconditionally at specified address.
NOP: No operation
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 (Grey)
Output: 2051 H- 6F (Binary)
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment