flat assembler
Message board for the users of flat assembler.

Index > Main > 'call' and 'push'

Author
Thread Post new topic Reply to topic
Patrick_



Joined: 11 Mar 2006
Posts: 53
Location: 127.0.0.1
Patrick_
I have code like the following:

Code:
push eax, ebx, ecx

push [argument]
call function

pop ecx, ebx, eax    


If I pushed the argument, when I then pop off ecx, does it pop [argument]?
Post 22 Apr 2006, 23:52
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
not if function handles it's stack properly
Post 23 Apr 2006, 00:07
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i am not sure if i understand you correctly, but if you are asking whether "function" removes [argument] from stack, then answer is that it depends on function (of course). There are several so-called calling conventions, most common are "pascal" (arguments pushed left to right, called procedure removes argument from stack), "stdcall" (arguments pushed right to left thus allowing variable number of arguments like with printf(), called procedure removes argument form stack) and "cdecl" (right to left, called procedure does NOT remove arguments, you must "add esp, size_of_arguments" after call.
Post 23 Apr 2006, 02:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
vid wrote:
i am not sure if i understand you correctly, but if you are asking whether "function" removes [argument] from stack, then answer is that it depends on function (of course). There are several so-called calling conventions, most common are "pascal" (arguments pushed left to right, called procedure removes argument from stack), "stdcall" (arguments pushed right to left thus allowing variable number of arguments like with printf(), called procedure removes argument form stack) and "cdecl" (right to left, called procedure does NOT remove arguments, you must "add esp, size_of_arguments" after call.


it is cdecl that allows many parameters "..." in C, because the stack is balanced after the procedure so the compiler or writer can calculate the needed bytes for the stack balance based on the number of parameters passed, printf is cdecl Smile

_________________
redghost.ca
Post 23 Apr 2006, 03:27
View user's profile Send private message AIM Address MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
RedGhost: yes, my mistake. But if you look deeper into it, you can't handle "..." in some "normal" way with C, you would have to do some pointer magic. So most of procs which take "..." are asm procs anyway. And in asm, you can clear the stack as needed inside procedure.

but it's theory, what you said is reality Wink
Post 23 Apr 2006, 10:21
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.