January 17, 2012
Write an assembly language program to swap content of memory location.
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to exchange the content between memory locations. Suppose 10 is store at 2050 and 11 is at 2051 then output should be 11 at 2050 and 10 should be at 2051.
Algorithm:
- Get First Number and store it in accumulator
- Get second Number
- Store it in another register C
- Now store first number at 2051
- Get 2nd Number in accumulator ant store it at 2050.
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
H,2050 H
|
Store First Number
|
2003
|
MOV
|
A,M
|
First Number in Accumulator
|
2004
|
INX
|
H
|
Get the 2nd number
|
2005
|
MOV
|
C,M
|
Store 2nd Number in C
|
2006
|
STA
|
2051
|
Store First Number at 2051
|
2009
|
MOV
|
A,C
|
Move number in accumulator
|
200A
|
STA
|
2050
|
Store 2nd number at 2050
|
200D
|
RST
|
5
|
Set Break-point
|
200E
|
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.
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-10, 2051-11
Output: 2050-11, 2051-10
Input: 2050-10, 2051-11
Output: 2050-11, 2051-10
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:10)
- Press ENTER and Provide your Input at location (2051:11)
- 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 (M2050) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment