assembly - Reverse a string using the stack -
i'm using dosbox , assignment. have reverse string using stack. thinking push string 1 character @ time onto stack pop out revstring 1 one. can't figure out how though. here have far.
.model small .stack 100h .data string db "najafi", 13, 10, "$" revstring db 6 dup(?), '.', 13, 10, "$" .code main proc ;; set ds register point data mov ax, @data mov ds, ax ;; printing string in dos mov dx, offset string mov ah, 9h int 21h ;; reverse string using stack mov ax, word ptr string push ax pop ax ;mov revstring, ax ;; print reverse string in dos mov dx, revstring mov ah, 9h int 21h ;; dos return mov al, 0 mov ah, 4ch int 21h main endp end main
to push string onto stack:
mov di, offset string mov cx, string_length xor ax, ax pushloop: mov al, [di] push ax inc di dec cx jnz pushloop
you can same type of thing pop characters stack revstring
.
Comments
Post a Comment