flat assembler
Message board for the users of flat assembler.
Index
> Main > proc macro bug |
Author |
|
Tomasz Grysztar 28 Oct 2006, 15:40
With proc32 the parameters on stack are always aligned up to occupy the multiply of 32 bits. If you define parameter of type BYTE, you still have to use the full 32-bit area for it, in order to keep the stack aligned properly. For this reason "invoke" and "stdcall" macros use "pushd" to store all the parameters.
However if you call the procedures without using a macros, you have to remember about the proper stack layout. If you look at other languages aswell, you'll notice that this is usual in the Win32 world, fasm's macros only adopted the existing standards. PS. The same applies to Win64 world, however there each parameter occupies 8 bytes - always. Even if it just a byte, the whole 64-bit area has to be reserved (though it doesn't have to be zero-filled). |
|||
28 Oct 2006, 15:40 |
|
AsmER 28 Oct 2006, 15:49
So if I want to pass some WORD value to my proc using the stack, then I will need to play with [EBP+XX] like a long time before. I didn't learn fasm macros syntax jet, but will it be possible to create a macro which would calculate it in the way I want?
|
|||
28 Oct 2006, 15:49 |
|
Tomasz Grysztar 28 Oct 2006, 16:33
Perhaps the most straightforward way is to not use macros at all (if you want to utilize the true power of assembly, no macros! ). Try this:
Code: push word [VW] push [VD] push [VD] push word [VD] call TESTP ; ... TESTP: virtual at ebp+8 .p1 dw ? .p2 dd ? .p3 dd ? .p4 dw ? .params_length = $ - (ebp+8) end virtual push ebp mov ebp,esp mov ax,[.p1] leave ret .params_length VW dd 0xFFFFFFFF VD dd 0xEEEEEEEE |
|||
28 Oct 2006, 16:33 |
|
Goplat 28 Oct 2006, 17:09
You're not supposed to push WORDs on the stack in 32 bit mode, since that misaligns your stack pointer, and according to official Intel docs that has performance implications.
If you push them in pairs it should be OK. Would something like this work? Code: ... push [VD] push [VD] push word [VW] push word [VD] call TESTP ... proc TESTP, p1:WORD, p3:DWORD, p4:DWORD label p2 WORD at p1+2 ... endp |
|||
28 Oct 2006, 17:09 |
|
AsmER 30 Oct 2006, 14:01
Thanks Goplat, it would work, but since I just wanted to save few bytes on the user's computer, I think I will change the structure of my program, so all variables will be 32bit, and I wont have any problems anymore
|
|||
30 Oct 2006, 14:01 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.