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 :

LocationMnemonicsHex Code
3000 LXI H 21
30010000
30022020
3003MOV A, M7E
3004INX H23
3005MOV B, M46
3006MOV C, A4F
3007MOV A, B78
3008MOV B, C41
3009MOV M, B70
300ADCX H2B
300BMOV M, A77
300CHLT76

INPUT AND OUTPUT :

LocationInput
200030
200150
LocationInput
200050
200130

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:

https://www.shoutcoders.com/sub8bitmp/
https://www.shoutcoders.com/microprocessor-8085a-program-given-two-data-stored-at-memory-location-x-and-x1-perform-addition-on-mx-and-mx1-and-store-the-result-at-location-x2/

Comments

Popular posts from this blog

MEMORY MANAGEMENT NOTE

MULTIPLY WITHOUT CARRY

SUBTRACTION