SWAP THE CONTENT
GIVEN TWO DATA STORED AT MEMORY LOCATION x AND x+1. SWAP THE CONTENT OF M(x) AND M(x+1).
THEORY :
In 8085 microprocessor, firstly we take two 8-bit numbers from the user and store it in different memory locations m(x) and m(x+1) respectively. Let, m(x) is 2000h and m(x+1) is 2001h. The SWAP operation will be done with the memory locations, registers, and the accumulator respectively.
ALGORITHM :
Step 1: LXI H,2000h; to load the address in H-L register pair using LXI H from 16-bit location 2000h.
Step 2: MOV A, M; to move the value of 2000h memory address value into the accumulator.
Step 3: INX H; to increase the value of the H-L register pair to get the next memory location.
Step 4: MOV B, M; to move the value of the 2001h memory location to register B.
Step 5: MOV C, A; to store the value of accumulator into the C register.
Step 6: MOV B, A; to store the accumulator value into the B register.
Step 7: MOV B, C; to store the C register value into the register B.
Step 8: MOV M, B; to store the B register value in memory location which is 2001h.
Step 9: DCX H; to decrease the value of H-L register pair.
Step 10: MOV M, A; to store accumulator value in memory location which is 2000h.
Step 11: HLT; to stop the program.
IMPLEMENTATION :
Location | Mnemonics | Hex Code |
---|---|---|
3000 | LXI H | 21 |
3001 | 00 | 00 |
3002 | 20 | 20 |
3003 | MOV A, M | 7E |
3004 | INX H | 23 |
3005 | MOV B, M | 46 |
3006 | MOV C, A | 4F |
3007 | MOV A, B | 78 |
3008 | MOV B, C | 41 |
3009 | MOV M, B | 70 |
300A | DCX H | 2B |
300B | MOV M, A | 77 |
300C | HLT | 76 |
INPUT AND OUTPUT :
Location | Input |
---|---|
2000 | 30 |
2001 | 50 |
Location | Input |
---|---|
2000 | 50 |
2001 | 30 |
DISCUSSION :
In this swapping program, we use two different memory locations where the user can give input. Data is loaded into the accumulator and B register. Swapping is done with the help of the C register. After swapping data is stored from the accumulator and B register to 2000h and 2001h memory locations.
YOU MIGHT LIKE:
Comments
Post a Comment