Data block Transfer using String Instructions
- Consider that a block of data of N bytes is present at source location. Now this block of N bytes is to be moved from source location to a destination location.
- Let the number of bytes N = 10.
- We will have to initialize this as count in the CX register.
- We know that source address is in the SI register and destination address is in the DI register.
- Clear the direction flag.
- Using the string instruction move the data from source location to the destination location. It is assumed that data is moved within the same segment. Hence the DS and ES are initialized to the same segment value.
Algorithm for Data block Transfer using String Instructions
Step I : You need to Initialize the data in the source memory as well as destination memory.
Step II : Initialize SI and DI with source and destination address.
Step III : Initialize CX register with the count.
Step IV : Initialize the direction flag to zero.
Step V : Transfer the data block byte by byte to destination.
Step VI : Decrements CX.
Step VII : Check for count in CX, if not zero go to step V else go to step VIII.
Step VIII : Stop.
Data block Transfer using String Instructions Program Code
src_blk db 01, 02, 03, 04, 05, 06, 07, 08, 09, 0AH
dest_blk db 10 dup(?)
count dw 0AH
mov ax, @data ; initialize data
mov ds, ax ; extra segment
mov es, ax
mov si, offset src_blk ; si to point to source block
mov di, offset dest_blk ; di to point to destination block
mov cx, count ; initialize counter
cld ; df=0
again : rep movsb ; transfer contents
mov di, offset dest_blk ; di to point to
mov bh, 0Ah ; initialize counter
up: mov bl, [di] ; store result in bl