8051 Program to exchange data block of 10 Bytes:
8051 Program to exchange data block of 10 Bytes, in this article we will be designing a 8051 Program to exchange data block of 10 Bytes, the actual code of the program is as follows:
Logic for 8051 Program to exchange data block of 10 Bytes:
The logic of this program is, initialize a pointer to data block 1, initialize second pointer to data block 2. We will be using indirect addressing mode to use both of the registers, ie. Pointers to Block 1 & Block 2. In 8051 only two registers R0 and R1 can be used in Indirect addressing mode, so we will be using both of them. In above program, data block 1 is stored at location 20H and block 2 is stored at location 30H. We initialize registers R1 and R2 as pointers to memory location 20H and 30H respectively. Register R2 is used as counter and loaded with 0AH, as we exchanging data block of 10 Bytes. We load first byte from data block 1 into accumulator (A). Using XCH A,@R1 we exchange the byte stored in A with the first byte of data block 2. After execution of this instruction, first byte from block 1 will be stored at first location of block 2. And the first byte of block 2 is present in accumulator so now, we move it from accumulator into first location of block 1. This is done using instruction MOV @R0,A. After execution of this instruction, the memory pointers are incremented to point next memory location. Program will take ten such cycles to exchange data blocks having 10 bytes stored. After execution of the program data blocks will completely be exchanged with one another. The code quoted above is tested and verified, in case of any doubts feel free to comment below.
Other articles you might like: