Friday, September 9, 2011

Statement: Write an ALP to reverse the contents of a block of N bytes and transfer the
reverse contents to destination block.

MVI C,0AH
LXI H,E000H
LXI D,E100H
BACK:
MOV A,M
STAX D
INX H
DCX D
DCR C
JNZ BACK
HLT
 
Explanation:
First of all initialize the counter. Here we have a source block of 10 bytes. Therefore, we stored 0AH data into register C.
HL pair is used to initialize source memory pointer. (In this program it is E000H)
DE pair is used to initialize destination memory pointer.(In this program it is E100H - if your destination block is starting at suppose any memory location 'wxyz' then intialize the DE pair with 'wxyz+counter value'as we want to store the reverse contents to destination block so we are DECREMENTING it by one. )

'BACK'  Loop:

The data stored in first memory location of source block(E000H) is copied to the accumulator.
The data of accumulator is stored in register D.

Memory pointer is incremented by 1. (HL register pair.)
Destination pointer is decremented by 1. (DE register pair.) As we want to store the contents in reverse.

Register C is decremented by 1. IF it is not equal to zero then it will again go to the 'BACK' loop.

HLT stands for 'stop'. :-)

No comments:

Post a Comment