Sunday, 15 December 2013

Reverse of String in Assembly Language Program


PROGRAM

.model small
.stack
print macro p
lea dx,p
mov ah,09h
int 21h
endm
.data
m1 db 0ah,0dh,"Enter the String: $"
m2 db 0ah,0dh,"Reverse String: $"
a db 20h dup("$");
b db 20h dup("$");
k dw 0
.code
mov ax,@data
mov ds,ax
mov es,ax
mov si,0000h
print m1

loop1: mov ah,01h
int  21h
mov a[si],al
inc si
inc k
cmp al,0dh
jne loop1

print m2
mov cx,k
mov di,0000h
dec si
dec si

loop2: mov bl,a[si]
mov b[di],bl
inc di
dec si
cmp di,cx
jne loop2

print b

mov ah,4ch
int 21h
end

OUTPUT

Enter the String:  india is my country
Reverse String:  yrtnuoc ym si aidni

No comments:

Post a Comment