StrReverse proc
uses ecx eax edi esi,
StrAdd1:dword, ;string 1 address
StrAdd2:dword ;string 2 address
std ;backward direction - set direction flag
push StrAdd2 ;address of str2 arg to StrlenAsm
call StrLenAsm ;get length of str2
;called function responsible for stack cleanup
mov ecx,eax ;length of string in ecx for rep
mov edi,StrAdd1 ;edi gets destination address for copy
mov esi,StrAdd2 ;esi gets source address for copy
loopTop:
lodsb ;
stosb ;
loop loopTop
mov byte ptr[edi],0 ;null terminate copied string
ret ;return control to caller
StrReverse endp
I know STD
is causing trouble, but I thought if I want reversing string, I should use std
...could anyone explain to me why is that wrong and giving hints how to fix it?
Thank you for any further helps!
EDIT: So like this?
StrReverse proc
uses ecx eax edi esi, ;
StrAdd1:dword, ;string 1 address
StrAdd2:dword ;string 2 address
push StrAdd1 ;address of str2 arg to StrlenAsm
call StrLenAsm ;get length of str2
;called function responsible for stack cleanup
mov ecx,eax ;length of string in ecx for rep
mov edi,StrAdd1 ;edi gets destination address for copy
mov esi,StrAdd2 ;esi gets source address for copy
add edi, ecx
loopTop:
cld ;forword direction - clear direction flag
lodsb ;read from source string
std ;backward direction - set direction flag
stosb ;write into distination string
loop loopTop
mov byte ptr[edi],0 ;null terminate copied string
ret ;return control to caller
StrReverse endp
It is still crashing =[