Author Topic: Procedures without LOCAL's don't restore ESP from EBP  (Read 593 times)

2B||!2B

  • Member
  • **
  • Posts: 85
Procedures without LOCAL's don't restore ESP from EBP
« on: August 16, 2021, 10:37:56 AM »
If a procedure has no LOCAL, it will not restore the stack from EBP.

Example of procedure with LOCAL

Code: [Select]
TESTPROC proc
LOCAL Dummy:DWORD

XOR EAX,EAX
ret

TESTPROC endp

Code: [Select]
PUSH EBP
MOV EBP,ESP
ADD ESP,-4
XOR EAX,EAX
MOV ESP,EBP
POP EBP
RETN 4

Removing LOCAL Dummy:DWORD would also make the procedure uses no MOV ESP,EBP before RET.

Code: [Select]
PUSH EBP
MOV EBP,ESP
XOR EAX,EAX
POP EBP
RETN 4

Is this the expected behavior or this is a bug?




jj2007

  • Member
  • *****
  • Posts: 11760
  • Assembler is fun ;-)
    • MasmBasic
Re: Procedures without LOCAL's don't restore ESP from EBP
« Reply #1 on: August 17, 2021, 03:50:29 AM »
Expected behaviour. Masm and Watcom assemblers may differ slightly, e.g. using a leave before returning.

2B||!2B

  • Member
  • **
  • Posts: 85
Re: Procedures without LOCAL's don't restore ESP from EBP
« Reply #2 on: August 17, 2021, 06:36:47 AM »
I didn't know this until recently. I have used few PUSH's without re-balancing the stack and it was working with UASM v2.48 if I remember correctly. Must've been added recently...

jj2007

  • Member
  • *****
  • Posts: 11760
  • Assembler is fun ;-)
    • MasmBasic
Re: Procedures without LOCAL's don't restore ESP from EBP
« Reply #3 on: August 19, 2021, 12:15:54 AM »
I didn't know this until recently. I have used few PUSH's without re-balancing the stack and it was working with UASM v2.48 if I remember correctly. Must've been added recently...

Check your non-volatile registers (esi edi ebx) saved via uses :cool: