FIND REVERSE OF EACH WORD IN A STRING - Assembly Language - MASM

Program:

        ;FIND REVERSE OF EACH WORD IN A STRING


.model small
.stack 200h
.data
msg1 db 10,13,'Enter the string:$'
msg2 db 10,13,'Reverse of the string:$'
newline db 10,13,' $'
buff db 60 dup(?)
flag db 0
stackempty db 1
.code
print macro msg
push ax
push dx
mov ah,09h
mov dx,offset msg
int 21h
pop dx
pop ax
endm
.startup
print msg1
print newline
mov si,offset buff
mov cx,0
mov bx,0
nxtchar:
mov ah,01h
int 21h
inc bx
cmp al,' '
je popy
cmp al,0dh
je popy
mov ah,0
push ax
mov stackempty,0
inc cx
jmp nxtchar
popy:
cmp stackempty,1
je stackkaali
cmp al,0dh
jne noflag
mov flag,1
noflag:
pop ax
mov [si],al
inc si
loop noflag
inc si
mov stackempty,1
cmp flag,1
je display
jmp nxtchar
stackkaali:
inc si
jmp nxtchar
display:
print msg2
print newline
mov si,offset buff
mov cx,bx
dispnxt:mov dh,0
mov dl,[si]
mov ah,2
int 21h
inc si
loop dispnxt
.exit
End
OUTPUT
F:\>rev
Enter the string:
kerala is called gods own country
Reverse of the string:
alarek si dellac sdog nwo yrtnuoc

3 comments:

  1. Thank you and looking for more posts. I am really satisfied with this posting that you have given us. This is really a stupendous work done by you.translation service

    ReplyDelete
  2. Well explained string operation .
    there are good String program collection visit Top String program

    ReplyDelete
  3. Thank you for sharing this useful blog with us.
    Do visit our website: Aluminium Bronze Bar, Aluminium Bronze Bar Manufacturers,

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...