Author Topic: Stack cleared in assembly  (Read 1357 times)

Offline xjapan2

  • Jr. Member
  • *
  • Posts: 3
Stack cleared in assembly
« on: April 21, 2017, 06:33:22 PM »
hello, im using assembly in delphi, but my program crash several times when I use this function for a long time...im finding that the problem is in "add esp, 04"


Code: [Select]
lea eax,value
push eax
call addr2
add esp,04
push 0
mov ecx,esi
mov eax,addr
call eax
add esp,04

other problem:


Code: [Select]
...
lea esi,[ecx+04h]
lea eax,test2
push eax
call addr2
add esp,04  //4*1 = 4 in hexadecial
push HP2
push esi
call Base
add esp,08 //4*2 = 8 in hexadecial
« Last Edit: April 21, 2017, 06:35:14 PM by xjapan2 »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2359
  • Country: us
Re: Stack cleared in assembly
« Reply #1 on: April 21, 2017, 07:01:30 PM »
Hi xjapan2,

Welcome to the Forum.

Your code does not appear to be for Nasm. (will not assemble, as posted) I'll take a guess that your functions are stdcall (or Pascal?), in which the callee cleans up stack. If that doesn't help, we'll need more information.

Best,
Frank


Offline xjapan2

  • Jr. Member
  • *
  • Posts: 3
Re: Stack cleared in assembly
« Reply #2 on: April 21, 2017, 07:12:17 PM »
Thanks, i liked this forum :)

yes, my codes are stdcall

look this:

Code: [Select]
push eax
push ecx
lea esi,value
push esi
push Key
mov ecx,Base4
mov ebx,Key
test ebx,ebx
je @Off
mov [edi],ebx
mov eax,Base5
call eax
add esp,10h //4*4 = 10 in hex
@Off:

Base1, Base2, Base3, Base4, Base5 are memory address of another program
« Last Edit: April 23, 2017, 04:12:47 AM by xjapan2 »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2359
  • Country: us
Re: Stack cleared in assembly
« Reply #3 on: April 21, 2017, 08:42:36 PM »
Thanks. I'm glad you like the Forum, but I doubt if we're going to be able to help you much. "Code is code", or so I like to claim, but syntax differs from one assembler to another. If your code is stdcall, trying to clean up the stack in the caller isn't going to work. That isn't a syntax issue.

Best,
Frank


Offline xjapan2

  • Jr. Member
  • *
  • Posts: 3
Re: Stack cleared in assembly
« Reply #4 on: April 21, 2017, 10:04:40 PM »
Thanks. I'm glad you like the Forum, but I doubt if we're going to be able to help you much. "Code is code", or so I like to claim, but syntax differs from one assembler to another. If your code is stdcall, trying to clean up the stack in the caller isn't going to work. That isn't a syntax issue.

Best,
Frank

I wanted to know how i clean the stack in this code? my knowledge in assembly is very limited  :(
I use this in a loop. and causes crash in 10 minutes, i would like to avoid it

I think i made the wrong use of the "add esp, 10h" :(

You can write in Nasm, i can convert to pascal.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2359
  • Country: us
Re: Stack cleared in assembly
« Reply #5 on: April 21, 2017, 10:16:35 PM »
If the code is stdcall, the procedure will end:
Code: [Select]
ret 10h
The caller shouldn't have to do anything at all to clean up the stack. Just comment out the "add esp, 10h". If it's taking 10 minutes to crash, this may not be the problem. Easy to try, anyway...

Best,
Frank