flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > The 64bit version of invoke (fastcall) makes extra code |
Author |
|
tthsqe 17 Jun 2014, 17:38
As you sure? the standard is that there is stack support for the arguments that are passed in registers...
|
|||
17 Jun 2014, 17:38 |
|
AsmGuru62 17 Jun 2014, 19:58
Maybe reserve these 20h bytes once in a procedure instead of doing it on each call.
|
|||
17 Jun 2014, 19:58 |
|
l_inc 17 Jun 2014, 21:23
madmatt
Have a look at the documentation about how to avoid stack allocation on each API call. _________________ Faith is a superposition of knowledge and fallacy |
|||
17 Jun 2014, 21:23 |
|
madmatt 17 Jun 2014, 23:27
l_inc wrote: madmatt Thanks! that seems to have solved the problem. why would stack space be allocated for each invoke call in the first place, if there is no need for it? _________________ Gimme a sledge hammer! I'LL FIX IT! |
|||
17 Jun 2014, 23:27 |
|
l_inc 18 Jun 2014, 00:35
madmatt
I think, it's obvious from the description of the frame macro: Quote: They should be used to enclose a block, inside which the RSP register is not altered between the procedure calls Just imagine what happens, if you try to save some register value between API calls onto the stack. P.S. I assume here, that you have the basic background knowledge regarding the "shadow space". _________________ Faith is a superposition of knowledge and fallacy |
|||
18 Jun 2014, 00:35 |
|
madmatt 18 Jun 2014, 01:21
l_inc wrote: madmatt the macro shouldn't reserve stack space for every invoke call, just every proc / endp. The programmer should decide whether extra stack space is needed per invoke call. I shouldn't have to use the frame/endf in every proc/endp function to stop this. _________________ Gimme a sledge hammer! I'LL FIX IT! |
|||
18 Jun 2014, 01:21 |
|
revolution 18 Jun 2014, 01:29
madmatt wrote: the macro shouldn't reserve stack space for every invoke call, just every proc / endp. The programmer should decide whether extra stack space is needed per invoke call. I shouldn't have to use the frame/endf in every proc/endp function to stop this. Code: invoke function,... push rax rcx invoke function,... pop rcx rax ;<--- what values are retrieved here if that stack allocation is static? |
|||
18 Jun 2014, 01:29 |
|
madmatt 18 Jun 2014, 13:06
revolution wrote:
The 64bit disassembly of my windows c code shows none of this kind of stack manipulation. 32bit cinvoke call required this, but not 64bit invoke / cinvoke calls. _________________ Gimme a sledge hammer! I'LL FIX IT! |
|||
18 Jun 2014, 13:06 |
|
l_inc 18 Jun 2014, 13:31
madmatt
Quote: The 64bit disassembly of my windows c code shows none of this kind of stack manipulation That's because a C compiler tracks stack content. This is possible because the instructions are generated solely by the compiler and the compiler can decide on it's own, if it puts something onto the stack in-between. fasm does not track, what you put onto the stack, and therefore cannot decide if "shadow space" is required. By using the frame macro you promise fasm to not do anything with the stack, and this way no stack allocation per call is required for code correctness. Quote: 32bit cinvoke call required this In fact, stack adjustment is not really necessary for the 32 bit cinvoke as well. In particular when the classical stack frame is in use: Code: push ebp mov ebp,esp ... ;unbalanced stack is not a problem here leave ret the unbalanced stack is automatically fixed during procedure return, and this way you could leave it as is by omitting add esp,X after each ccall-function invocation. But again register value saving within such a frame would break code correctness. Ensuring it requires fasm to adjust the stack frame each time. _________________ Faith is a superposition of knowledge and fallacy |
|||
18 Jun 2014, 13:31 |
|
madmatt 19 Jun 2014, 11:05
l_inc wrote: madmatt But if code works fine without this code, why add the code in the first place? Why should I have to use frame/endf every proc/endp just to turn this 'feature' off? All I'm asking for is a simple fix that will remove this code without the use of frame/endf. So Tomasz, is there a simple fix for this, without the use of frame/endf? _________________ Gimme a sledge hammer! I'LL FIX IT! |
|||
19 Jun 2014, 11:05 |
|
l_inc 19 Jun 2014, 11:32
madmatt
Oh, come on. The code does not always work fine. I gave an example before. revolution even provided code for that example. The question is just about what guarantees you'd prefer to have: guarantees of small code or guarantees of correct code. The latter choice is nearly always the defaults. That is why you need additional coding overhead for having smaller code. _________________ Faith is a superposition of knowledge and fallacy |
|||
19 Jun 2014, 11:32 |
|
revolution 19 Jun 2014, 12:49
madmatt wrote: All I'm asking for is a simple fix that will remove this code without the use of frame/endf. Code: include 'win64ax.inc' macro proc [args] { common proc args frame } macro endp { endf endp } section '.text' code readable executable entry start entry equ nul proc start fastcall function,0,1,2,3,4,5 fastcall function,0,1,2,3,4,5 fastcall function,0,1,2,3,4,5 invoke MessageBox,0,'hi','ho',0 invoke ExitProcess,0 endp proc function a1,a2,a3,a4,a5,a6 ret endp .end 0 |
|||
19 Jun 2014, 12:49 |
|
Tomasz Grysztar 19 Jun 2014, 15:45
madmatt wrote: But if code works fine without this code, why add the code in the first place? Why should I have to use frame/endf every proc/endp just to turn this 'feature' off? All I'm asking for is a simple fix that will remove this code without the use of frame/endf. So Tomasz, is there a simple fix for this, without the use of frame/endf? See also the original thread when I introduced the "static RSP" macros, it has the example disassembly. |
|||
19 Jun 2014, 15:45 |
|
madmatt 21 Jun 2014, 00:46
Tomasz Grysztar wrote:
Thank you, works how I want it to now. By the way, you're right, some instructions are larger, but some instructions are smaller too. _________________ Gimme a sledge hammer! I'LL FIX IT! |
|||
21 Jun 2014, 00:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.