; reverse string
mov ah,0ah
lea dx,parameter
int 21h
mov ah,02
mov dl,0ah
int 21h
mov dl,0dh
int 21h
; initialize
xor cx, cx ; zero out cx
lea si, origstring ; si = inputted string
mov cl, [actlen] ; cl = length of inputted string
dec cl ; since string starts from 0 to cl-1
lea di, revstring ; di = empty
add di, cx
reverse:
mov al, [si] ; get character
mov [di], al ; copy to di at ‘cl-1′th position
dec di
inc si
cmp al, ‘$’ ; means end of string
jne reverse
mov ah, 09
lea dx, revstring
int 21h
int 20h
parameter label byte
maxlen db 0FF
actlen db ?
origstring db 0FF dup(’$')
revstring db 0FF dup (’$')
All comments are moderated. Your comments will not appear here unless approved by the blog owner. Thank you.