Hello, I would like to save the address of a function anywhere and woud like to call the funcrion in help with the variable wich contains the stored function-address.

command1 PROTO
Label1

MOV EDI, LAbel1

how does i work realy ?

I want to call after storing a function or a label.

I hope you you know what I mean.
Posted on 2003-04-18 15:01:39 by Forginforcer
Hint - there is a directive named OFFSET
Posted on 2003-04-18 15:16:34 by donkey
Jear, the problem is, whether it works, if have two languages.
I know, that the parameters were overgifen at the stackt, but how its realy wokrs ?
Posted on 2003-04-18 16:20:57 by Forginforcer
If this involves passing data between two languages it really belongs on the heap. What is it you are trying to do ? Are you attempting to call an ASM function from another language and want to pass data between them ?

A general rule is that any information that has been declared as LOCAL is going to be lost and any pointers to that data are useless after the ret instruction is executed and the local stack is destroyed. If you want data to be used after the procedure has been executed you must declare the variable as a global or allocate a heap and store it there. If you have only one value you wish to preserve put it in eax, that is the convention for returned values. Passing those values from one language to another differs from language to language and those questions belong on the heap.
Posted on 2003-04-18 16:32:37 by donkey
I thought, I could call an assembler routine with an parameter(a function of the c++ programm), and call it from the assembler routine.

do you mean that with EAX ?:

how to call/jump to the adresse ?
JMP OFFSET ... ?
Is it right to get the adress with MOV EDI, Label1 ? :confused:

Thanks for replys
Posted on 2003-04-18 16:44:18 by Forginforcer
Test1 proc Param1,Param2,Param3
;blah blah blah
ret
Test1 endp

to call it :

push Param3
push Param2
push Param1
call Test1

or

invoke Test1,Param1,Param2,Param3

From inside another procedure with Local Var

LittleProc proc
LOCAL MyVar :DWORD

mov MyVar,10
push MyVar
push Param2
push Param1
call Test1

or

invoke Test1,Param1,Param2,MyVar
ret
LittleProc endp

If you want to do it in another language post in "The Heap"
Posted on 2003-04-18 16:57:56 by donkey
Try this:



mov foo, ADDR <your function>
push <your parameter>
call [foo]
Posted on 2003-04-18 17:00:24 by sluggy
Hey sluggy, you exacty understood, what I meand.
Wich type foo have to be ? - DWORD ?
Does it run also with labels ?

Thanks !
Posted on 2003-04-18 17:06:16 by Forginforcer

Hey sluggy, you exacty understood, what I meand.
Wich type foo have to be ? - DWORD ?
Does it run also with labels ?

Thanks !


Hmm... Sluggy, i thought "addr" only worked /w "INVOKE"? of course, i could be wrong (and probably am ;) ). i normally use lea/mov offset for this kind of thing.

Forginforcer, you're working in Win32Asm, i'm assuming? If so, then, yes, of course foo is a dword. Win32 uses 32-bit addresses, so anything else would make no sense. and while i can't say whether or not it works with labels (although i don't see why not), you could try it yourself and tell us what happens :tongue:

BTW, you can pass the address through invoke much the same way as you would for creating a window:
invoke CallerFunction,addr pFuncToBeCalled
Posted on 2003-04-18 18:27:34 by jademtech
1. Jademtech your right, ADDR does not work with MOV you have to use OFFSET as I said originally.

2. Sluggy's example (even if it worked) is just adding an extra instruction for nothing. MASM treats labels as a pointer to an address when it assembles the program so all you are doing is moving one pointer into another pointer. blah1 into blah2 and calling it something different when it isn't, just use the original label name instead. If you need the actual address use mov eax,OFFSET <your function>.

3. Red, I told you to check OFFSET at the start of all of this, did you read the entry on that operative ? It seems that it is exactly what you wanted, the help file entry on OFFSET is very clear and easy to follow.
Posted on 2003-04-18 19:06:31 by donkey
2. Sluggy's example (even if it worked) is just adding an extra instruction for nothing. MASM treats labels as a pointer to an address when it assembles the program so all you are doing is moving one pointer into another pointer. blah1 into blah2 and calling it something different when it isn't, just use the original label name instead. If you need the actual address use mov eax,OFFSET <your function>.
It was never tendered as a 'working' example, only as an example of how it should be done. I should have used 'OFFSET' instead of ADDR, whoops, me bad.

MASM treats labels as a pointer to an address when it assembles the program so all you are doing is moving one pointer into another pointer.
It depends on what you are doing with the function address. Personally, i prefer to take the 'penalty' of the extra instruction, and keep the purpose of the code crystal clear.


blah1 into blah2 and calling it something different when it isn't, just use the original label name instead.
This line makes no sense, the way i read it he doesn't have the original label available at the time he wants to call that function.


But despite all this arguing, at least the problem is solved :)
Posted on 2003-04-18 20:50:06 by sluggy
Sorry, sluggy, I didn't mean it sound like an attack on you though I guess it came out that way. He said in the first post that he had the label (MOV EDI, LAbel1) so I figured that he was just doing alot of wondering about nothing. the Blah1 into Blah2 thing was supposed to say something like :

If you take a label and move it's offset into another variable that variable essentially becomes the same as the label itself. That defeats the purpose of using labels in the first place.

I was just a little frustrated that I answered all the questions about stacks and stuff that he asked then find out that my first post pretty much covered the question anyway. All he had to do was read the section about offsets

Again, I appologize :)
Posted on 2003-04-18 20:56:57 by donkey
Thanks @
I've understoot something wrong. Beecause my exaple didn't work, as sou can see at my post.

I'm very sorry !

Thanks a lot I will try it after taking a shower ! :cool:
Posted on 2003-04-19 02:38:43 by Forginforcer
You can try


mov eax, OFFSET foo
call [eax]

Posted on 2003-04-19 03:15:28 by roticv
Again, I appologize :)
Hey, no worries :grin: Most of my answers tend to be typed very late at night, that is why i made such a simple mistake. Done it a hundred times before, will do it a hundred times more :)


If you take a label and move it's offset into another variable that variable essentially becomes the same as the label itself. That defeats the purpose of using labels in the first place.
This is absolutely correct. What i was inferring from your original statement was that MASM can treat function declarations (i.e. PROC blah USES.....) as a label. Is that correct, or have i invented a quirk/feature that doesn't exist?
Posted on 2003-04-20 06:39:40 by sluggy

You can try


mov eax, OFFSET foo
call [eax]




Hmmm i don't think so :)



mov eax, OFFSET foo
[B]call eax[/B]
Posted on 2003-04-20 06:53:57 by Axial