The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: hellbike on July 01, 2009, 07:18:35 AM

Title: question about calling function and heap
Post by: hellbike on July 01, 2009, 07:18:35 AM
i want to push some valules, then i want to call a function - in function i want to pop those values, and then i want to ret. But after calling function, at top of heap is adress of next instruction, so that wont work.

Did i solved this problem right? is this gonna work? - http://nopaste.gamedev.pl/?id=4082 (im using fasm, but i dont think that make any difference.
Title: Re: question about calling function and heap
Post by: dedndave on July 01, 2009, 12:20:45 PM
no
you may access data on the stack, then let the RET instruction remove them after you are done

        push    val2
        push    val1
        call    function
.
.
.
function PROC

        push    ebp
        mov     ebp,esp
        mov     eax,[ebp+8]   ;val1
        mov     edx,[ebp+12]  ;val2
.
.
.
        pop     ebp
        ret     8             ;return, then pop 8 bytes

function ENDP

notice that [ebp] is the saved ebp value, and [ebp+4] is the return address for the CALL - [ebp+8] is the last-pushed parameter

the INVOKE directive may also be used

        invoke  function,val1,val2

there are also other ways to access them in the PROC

now, you may pop them off the stack inside the PROC if you like, but it isn't neccessary...

function PROC

        pop     ecx           ;return address
        pop     eax           ;val1
        pop     edx           ;val2
        push    ecx           ;put the return address back on the stack
.
.
.
        ret

function ENDP

the MASM manual explains the other ways of accessing the values as LOCAL variables
Title: Re: question about calling function and heap
Post by: ToutEnMasm on July 01, 2009, 12:52:20 PM
 :lol
don't use invoke , proc and all this sort of things like macro,structures ....
The best write is this one
Quote
0000072C  6A 00                     ;    push   +000000000h
0000072E  E8 00000000     ;    call   ExitProcess
Title: Re: question about calling function and heap
Post by: dedndave on July 01, 2009, 01:12:45 PM
now, now, Yves
let's not confuse the new guy   :naughty:
(http://avatars.jurko.net/uploads/avatar_23077.gif)
Title: Re: question about calling function and heap
Post by: ToutEnMasm on July 01, 2009, 02:01:42 PM

No confuse,it's so best that I let it done by a listing !

Quote
BUT Now ,I think I need my grand Mother !
Title: Re: question about calling function and heap
Post by: dedndave on July 01, 2009, 03:03:55 PM
Granny can't save you, now