Search code examples
assemblystackmasmirvine32

Copying string in reverse order using push and pop in Assembly,can't see output by calling writeString


Only Problem is that i can't see output by calling writeString to make sure that string is successfully copied into destination or not

INCLUDE Irvine32.inc

.data
string BYTE "kashif",0
dest  BYTE 0
.code
main PROC

mov ecx,lengthof string
mov esi,offset string

k:
mov al,[esi]
push ax
inc esi
loop k

mov ecx,lengthof string
mov edi,offset dest

a:
pop ax
mov [edi],al
call writeChar
inc edi
loop a

by calling writeChar i can see output in reverse order i.e fihsak it means that push,pop is working fine

mov edx,offset dest
call writeString 

but here i can't see any output by calling writeString

exit
main ENDP

END main

Solution

  • Reversing a string does not make it any longer or shorter. You need to initialize the destination the same way you setup the source.

    string BYTE "kashif",0
    dest   BYTE "xxxxxx",0
    

    Here the lengthof operator returns 7 because it will include the terminating zero. That terminating zero is not a byte you want to include in the reversing operation and so you must decrement the count.

    mov ecx,lengthof string
    dec ecx