News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Passing a structure

Started by Farabi, January 28, 2008, 02:49:25 AM

Previous topic - Next topic

Farabi

Im a bit confuse about this code. What is the different when MASM compile it


Test Proto :POINT
Test Proto :dword,:dword

.data
p:POINT
.code
invoke Test,p
invoke Test,p.x,p.y
invoke Test, addr p


Thanks for the answer.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Vortex

When you have a lot of parameters to pass to your function, it's preferable to use a structure defining all the parameters and then pass an address pointing the structure to the function. This makes easier the calls to functions with a lot of parameters.

Don

Hi Farabi, there is a big difference between passing variables by value or by address. Of course it depends on what the Test proc is expecting  :wink

if you use "invoke Test, p" you are sending the contents (or value) of p to the Test procedure.
If you use the "ADDR p" alternative you are passing the memory address of p in memory to the Test procedure.

It gets even more complicated as you are passing a POINT structure. A good place to get an idea is in the Addressing and Pointers section in the asmintro help file (\masm32\help\asmintro.hlp).

Regards, Don.

donkey

Hello Farabi,

Other than the obvious, there is another fundamental aspect of argument passing that separates passing by value and passing by pointer. When you pass an argument by value the procedure that is called cannot modify the contents of the buffer, while passing them by pointer allows the callee to do so. This is a very important distinction that can allow you to add quite a bit of flexibility to your program and power to procedures and is the primary reason many API functions require passing arguments by pointer.

Donkey
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

raymond

Another argument to prefer passing a pointer to a structure (instead of the data) is that, if the procedure must call some other procedure with the same data, it can do so with a single argument instead of passing another multitude of them. Also saves time due to less typing!!! :wink
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com