PROC definition

procname proto :POINT, :RECT

procname proc point:POINT, rect:RECT
mov eax,.x
procname endp

PROC usage that works (memory operand)

local point:POINT, rect:RECT
invoke procname, ,

PROC usage that doesn't work (immediate data)

invoke procname, 1,2, 3,4,5,6

Anyone knows how to implement the last example?

Maybe even with regs? invoke procname, 1,eax, 3,4,ecx,edx

Best regards,
Posted on 2007-12-12 03:11:40 by aleksaZR
one way is bypassing the invoke directive

push 6
push 5
push 4
push 3
push 2
push 1
call procname


Posted on 2007-12-12 04:27:24 by Biterider
I would rather pass a pointer referencing the stucture to the procedure.
Posted on 2007-12-12 13:20:09 by Vortex
The procedure:
procname proc \
dstX, dstY,\ ;destination pixel
srcX, srcY,\ ;source pixel
sizX, sizY ;rect size

could as well be written as:
procname proc \
dst:POINT,\ ;destination pixel
src:POINT,\ ;source pixel
siz:SIZE ;rect size

the stack is absolutely the same, but it looks better (to me).

IMHO, passing a pointer is more suited for larger structures.
(altough I'm not quite sure, even with structs like POINT)

Biterider, I don't like bypassing the invoke with call, too ugly.

After all, I guess I'll use separate params.

Thanks all
Posted on 2007-12-13 07:19:54 by aleksaZR
If theres more than one param, and the params are closely related to each other, its worth passing as a pointer.
How many wasted pushes and pops are you generating by having procedures with more parameters than are required?

I'm thinking to myself that a 3D vector structure is a good example, its only 3 dwords long, but then agan, the amount of wasted pushes and pops is multiplied by how intensively you call that procedure... which for something like a Vec3 (or more complex vertex structure), can be a lot.
If the procedure is the guts of some loop or other, and its getting called thousands of times, you are pushing and popping thousands of times, and what are we gaining?

I say it depends very much on how often (and by whom) the procedure is expected to be used.
Some modern code environments do not allow pointer-based access across code modules, and in such cases we have no choice, but pointers are generally the fastest and cheapest choice, and if that choice is available to us, we should certainly consider using it, if not in the first draft of the code, perhaps in the final build.

Usually, if I am for some reason unable to address a structure via its Pointer, I will address it via its Index (in some array) instead.
The result is the same, that we pass a single parameter that represents the larger structure, noting that eventually a pointer will be calculated and shoved into some register, its just a question of when and where.

Posted on 2007-12-14 22:59:06 by Homer