News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

leave trashes esp

Started by jimg, April 09, 2020, 11:12:24 AM

Previous topic - Next topic

jimg

I've been searching for a bug all day that causes masm 6.14 and 6.15 to crash, but no uasm.

Here's a little prog that shows the problem
include \masm32\include\masm32rt.inc

.code
PutString proc locx
   pusha
   mov esi,locx
   .repeat
      lodsb
      or al,al
      .break .if zero?
      invoke crt__fputchar,al
   .until 0
   popa
ret
PutString endp

.data
testx db "test",0
.code
program:
nop
   invoke PutString,addr testx
nop
inkey "exit?"
invoke ExitProcess,0   
end program


Tracing in Olly, I find that the leave at the end of the proc trashes esp, so the proc returns to some random spot and crashes.

I vaguely seem to recall something nasty about leave in the past, but I've never had masm crash like this before.  Is there something in this code that causes the problem?

jj2007

Leave is innocent:
mlv615
enter repeat    x:esp           0018FF60
test
exit repeat     x:esp           0018FF58

UAsm64
enter repeat    x:esp           0018FF60
test
exit repeat     x:esp           0018FF60


Remember that leave depends on ebp, and that you are using pushad+popad. Masm handles invoke crt__fputchar,al differently - call it a bug.