;Copy a string backwards ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .model small .586 .stack 100h ;Set maximum stack size to 256 bytes ;; declare externally used subroutines extrn Writestring:proc, Crlf:proc, Clrscr:proc, Writeint:proc extrn Random_range:proc, Randomize:proc, Readint:proc .data msg1 db "The devil speaks like this!", 0h msg2 db "Yet another string",0h msg3 db "madam Im adam",0h dest db 80 dup (?) ; .code START: mov ax, @data ;ax <-- data segment start address mov ds, ax ;ds <-- initialize data segment register mov dx,offset msg1 mov si, offset dest call pback mov dx, offset msg2 mov si, offset dest call pback mov dx, offset msg3 mov si, offset dest call pback EXIT: mov ax, 4c00h ;ax <-- 4c DOS 21h program halt function int 21h ;DOS service interrupt ;; copy string in dx to si backwards, print both strings pback proc push si ;; save SI call Writestring call Crlf mov bx,dx ;; find end of first string xor cx,cx ;; keep count of # of characters lp1: mov al, [bx] inc bx inc cx cmp al,0 jne lp1 ;; bx points at 1 location past end of string ;; point at last character by decrementing twice dec bx dec bx dec cx ;; copy string to where SI points lp2: mov al,[bx] mov [si], al dec bx inc si loop lp2 ;; mark end of copied string xor al,al mov [si],0 pop si ;; restore SI mov dx,si ;; print copied string call Writestring call Crlf ret pback endp END START