GIVEN TWO DATA STORED AT MEMORY LOCATION x AND x+1. SWAP THE CONTENT OF M(x) AND M(x+1).
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.
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.
|3003||MOV A, M||7E|
|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|
|300B||MOV M, A||77|
INPUT AND OUTPUT :
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: