Transfer block of N bytes from source to destination
Algorithm for Transfer block of N bytes
Step I : Initialize the data in the source memory and 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 : Decrement CX.
Step VII : Check for count in CX, if not zero goto step V else goto step VIII.
Step VIII : Display the bytes in destination location.
Step IX : Stop.
Transfer Block of N Bytes Code
1 |
.model small <br/> .data <br/> src_blk db 01, 02, 03, 04, 05, 06, 07, 08, 09, 0AH <br/> dest_blk db 10 dup(?) <br/> count dw 0AH <br/> .code <br/> mov ax, @data ; initialize data <br/> mov ds, ax <br/> mov es, ax <br/> mov si, offset src_blk ; si to point to source block <br/> mov di, offset dest_blk ; di to point to destination block <br/> mov cx, count ; initialize counter <br/> cld ; df=0 <br/> again : rep movsb ; transfer contents <br/> mov di, offset dest_blk ; di to point to <br/> ; destination block <br/> mov bh, 0Ah ; initialize counter <br/> up: mov bl, [di] ; store result in bl <br/> mov cx, 0204h ; Count of digits to be <br/> displayed in <br/> ; ch and digits to be <br/> mrolled in cl <br/> l1: rol bl, cl ; roll bl so that msb comes <br/> to lsb <br/> mov dl, bl ; load dl with data to be <br/> displayed <br/> and dl, 0fh ; get only lsb <br/> cmp dl, 09h ; check if digit is 0-9 <br/> ; or letter A-F <br/> jbe l12 <br/> add dl, 07h ; if letter add 37H <br/> ; else only add 30H <br/> l12: add dl, 30h <br/> mov ah, 02 ; Function 02 under <br/> ; INT 21H <br/> int 21h <br/> dec ch ; Decrement Count <br/> jnz l1 <br/> dec bh ; decrement counter <br/> inc di <br/> mov ah, 02h ; display space <br/> ; between bytes <br/> mov dl, ' ' <br/> int 21h <br/> cmp bh, 00h ; repeat till all bytes <br/> ; are displayed <br/> jne up <br/> mov ah, 4ch ; normal termination <br/> ; to dos <br/> int 21h <br/> end |
Source projectgeek.com