Hi, it's me again. I would like to call two different functions, both of which are stored in an array such as below:

push D1
push D2
call .function ;eg. function pointer-type thingy

push D1
push D2
push D3
push D4
push D5
push D6
call .function ;yet another

I can either push D1-D6 and zero out the non-used parameters being passed (making all the functions take same number of params), or.. I can see if the related function in the array's what I call 'parameter list definition' is set to 2 (for short), 4(for int), etc.. if so then push the relative D1-D6 and would look something like the calls above only with .IF statements.

Question: is there another way, or one of the above ideal? This will be going in a continuous loop and the more smooth/speed there is the better.

Thanks.
Posted on 2003-12-08 20:31:46 by drarem
Or, make your function use C calling convention and clean up the stack yourself - like VARARG. For example,


.data
p1 dd f1 ; dword f1(dword i)
p2 dd f2 ; dword f2(dword i, dword j)

.code
...
push d1
push d2
call dword ptr p1 ; p1 does not use d1 at all
add esp,8

push d1
push d2
call dword ptr p2 ; p2 uses d1 and d2
add esp,8
Posted on 2003-12-08 21:07:16 by Starless
alrighty, i tried the following test and got a memory read error..



::
.data
FileOpen dd my_fopen ;wonder if I can directly substitute some API's..
::
::
push 0
push 0
push 0
push 0
push 0
push 0
push 0
push 0
call dword ptr FileOpen
add esp,32 ; 8 pushes * 4 (sizeof dword) = 32


The FileOpen function takes 8 parameters.

in my proc, there is a ret at the end - not sure if that is still required when you do a call..

ok I figured it out, I don't need the add esp,32 because when I push the parms onto the stack, the function parms pull it off..



my_fopen PROC d1:DWORD, d2:DWORD, d3:DWORD, d4:DWORD, d5:DWORD, d6:DWORD, d7:DWORD, d8:DWORD

:: ::
ret
endp


why is there stack restoration via add esp when the proc cleans it up automatically? Or is there another way to code a proc?

thanks
Posted on 2003-12-12 16:47:14 by drarem
Starless suggested that you use C-calling convention whereby the function you call does not clear up the stack. This task is left to the code that calls it.
Posted on 2003-12-12 21:54:54 by roticv
err.... doh! Thanks
Posted on 2003-12-13 10:57:03 by drarem