Hello,

I tried to push and pop some parameters.
Code doesn't work. Any suggestions ?

WinMain proc ....
...
call getparams
pop y1
pop x1
...
WinMain endp


getparams proc
local x : dword
local y : dword

...calculate x and y

push x
push y

ret 0
getparams endp
Posted on 2002-02-27 17:12:49 by Jurgen
Jurgen,

Without knowing the details of the machine code, I am guessing that the problem is related to the PROC stack preservation code. Usually you do you own stack work within the scope of a proc, not across it as the exit code for a proc restores the entry code in terms of stack location.

Regards,

hutch@movsd.com
Posted on 2002-02-27 17:31:25 by hutch--
You could always do something like this inside your proc:

mov eax, x
mov edx, y

then retrieve these values after the proc, that way you'll save a few cycles from the push/pop.

mov x1, eax
mov y1, edx

How's that? :)
Posted on 2002-02-27 17:35:45 by stryker
I see, its confusing to me

I gonne use EAX and EBX instead to return the parameters

thanks
Posted on 2002-02-27 17:50:25 by Jurgen
IMHO It is because locals usage.
Masm at the end adds code wich clear stack.
As I said for 100 times - use debugger - everything will be clear in seconds - it shows your absolutly everything in each step of code including what's going on in stack.
Posted on 2002-02-27 19:21:38 by The Svin
your code might caused this results..

1. when you call getparams...
IP address pushed
local x pushed
local y pushed
and your another
push x
push y

so your pushed bytes is totally 4 * 5 = 20bytes

2. when your proc returns it will pops 12 bytes
(IP, and local variables)
stack is FIFO(First In First Out), so stack pointer indicates
your local variable "x".
3. when you pops y1, x1 after returns getparmas,
it will matches like this

y1 = x(getparams's local variable)
x1 = IP(it may be the offset of "pop y1")

regards....



==
WinMain proc ....
...
call getparams
pop y1
pop x1
...
WinMain endp


getparams proc
local x : dword
local y : dword

...calculate x and y

push x
push y

ret 0
getparams endp
==
Posted on 2002-02-27 19:30:22 by muzidowa
Thanks for the response.

I finally centered my window on the screen :)
Posted on 2002-02-27 20:15:48 by Jurgen