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 shift a 16-bit number right by one bit.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: Assume that data is stored in memory location 2500 and 2501 H. Store the result in 2502H and 2503 H.
 
Algorithm:
  • Load number at given location
  • Store content higher byte in Accumulator
  • Rotate right the content of accumulator
  • Move D in Accumulator
  • Add H and D and store output in H
  • Store content of H and L at given location
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LHLD
2500 H
Get First Number
2007
MOV
A,H
Save data of H in A  
2008
RAR
Rotate right accumulator
2009
MOV
H,A
Save data of A in H  
200A
MOV
A,L
Move Content of L into A
200B
RAR
Rotate right accumulator
200C
MOV
L,A
Save data of A in L
200D
SHLD
2502 H
Store output
2010
RST
5
Set Break Point
2011
END
End the program
 
Used Instruction:
LHLD addr: This instruction copies the contents of memory location given within the instruction into L register and contents of next memory location into the H register. 
MOV rd,rs: This instruction copies data from the source register into destination register. 
RAR: Rotates the bits of accumulator right by one position, through the carry 
SHLD: The contents of register L are stored in the memory location specified by the 16-bit address in the operand and the contents of register H are stored in the next memory location. 
RST 5: This instruction is used to set break-point for the execution. 
END: This instruction is used to execute the program.
 
Result:  
Input:  
Number-3412 
2500-12 
2501-34 
Output: 
2502-09 
2503-1A 
 
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 (M2500)
  •  Press ENTER and Provide your Input at location (2500:12)
  •  Press ENTER and Provide your Input at location (2501:34)
  •  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 (M2502) and press ENTER
  •  You will get your desired output.

No comments:

Post a Comment