Program to reverse a string
Program
; PROGRAM: REVERSE A STRING
print macro s
mov ah, 09h
mov dx, offset s
int 21h
endm
data segment
msg db 'Enter a string: $'
nl db 0dh,0ah,'$'
str db 50 dup('$')
rev db 50 dup('$')
data ends
code segment
assume ds:data, cs:code
start:
mov ax, data
mov ds, ax
print msg
mov si, offset str
mov dh, 00
mov ah, 01h
LOOP1:
int 21h
cmp al, 0dh
jz STOP
mov [si], al
inc si
inc dh
jmp LOOP1
STOP:
mov di, offset rev
dec si
LOOP3:
cmp dh, 00
jz FINISH
mov bh, [si]
mov [di], bh
inc di
dec si
dec dh
jmp LOOP3
FINISH:
print nl
print rev
mov ah, 4ch
int 21h
code ends
end start
0 comments:
Post a Comment