Wednesday, February 16, 2011

Reverse each words in a sentance

Share Orkut
;to print a string print macro msg lea dx,msg mov ah,09h int 21h endm ;goes to next line newline macro mov ah,02h mov dl,0ah int 21h endm .model small .stack 100h .data s1 db 'Enter the sentance:- $' s2 db 'Sentance after reversing the word:- $' s3 db 50 dup('$') .code mov ax,@data mov ds,ax print s1 mov di,00h ;read s3 loop1:mov ah,01 int 21h cmp al,0dh jz j1 mov s3[di],al inc di jmp loop1 ;length of s3 is stored in cx j1:mov cx,di mov di,00 mov bx,sp newline print s2 ;while cx!=0 ;{ ; if s3[di]==' ' ; { while stack not empty ; pop and display ; display space ; } ; else push s3[di] ; increment di ; decrement cx ;} loop2:cmp cx,00 jz loop4 mov al,s3[di] cmp al,32d jnz j4 loop3:cmp sp,bx jz j3 pop dx mov ah,02h int 21h jmp loop3 j3:mov ah,02h mov dl,32d int 21h jmp j5 j4:mov ax,00 mov al,s3[di] push ax j5:inc di dec cx jmp loop2 ;while stack not empty ; pop and display loop4:cmp sp,bx jz stp pop dx mov ah,02h int 21h jmp loop4 stp:mov ah,4ch int 21h end

No comments:

Post a Comment