flat assembler
Message board for the users of flat assembler.
Index
> Windows > Does 64-bit invoke need to destroy RAX if argscount > 4? |
Author |
|
typedef 14 Feb 2015, 00:29
Why are you passing RAX?
|
|||
14 Feb 2015, 00:29 |
|
revolution 14 Feb 2015, 02:03
You could choose any register instead of RAX but you still need to make some other changes to keep the macro working. Maybe:
Code: ;... sub rsp,... ;allocate the stack mov [rsp],reg ;save the register you use for temporary values ;... if param eq reg mov r8,[rsp] ;example for third parameter (r8) ;... |
|||
14 Feb 2015, 02:03 |
|
fatygant 14 Feb 2015, 08:53
@typedef
It's not me who passes RAX - it's Windows ABI. I am asking because I wanted to avoid the situation where I am calling function A which gives me its result in RAX and in the next step I want to pass this value to function B as fifth parameter let's say. In present shape of 64-bit fastcall/invoke macros I have to do one more thing before calling function B: mov RSI, RAX for example (and remember to add 'uses RSI' statement to proc definition). I think that it would be nice if fastcall checks if one of the parameters is being passed in register which it internally uses (RAX at the moment) and saves it somehow. I could see on internet that NASM users had similar problem in the past and someone was trying to modify NASM's invoke macro in a way not to destroy RAX contents. However I am dealing too shortly with fasm and assembly in general to try to do it by myself. For now I just have to remember that RAX gets scratched if used as register passing fifth, sixth, seventh, etc. function parameter. |
|||
14 Feb 2015, 08:53 |
|
revolution 14 Feb 2015, 12:08
It all comes down to what you do when the register you use as a scratch is also an input value. My example above places it in the first slot of the spill area, but this would need some extra code to make it efficient and only save it there when it is needed.
Last edited by revolution on 14 Feb 2015, 15:42; edited 1 time in total |
|||
14 Feb 2015, 12:08 |
|
fatygant 14 Feb 2015, 15:38
Yes, revolution - exactly.
I started this thread only because the behaviour of 64-bit fastcall/invoke surprised me pretty much. Now, when I know how it works (regarding RAX handling) - I can live with this. I hope this will help some other fasm greenhorns... |
|||
14 Feb 2015, 15:38 |
|
revolution 14 Feb 2015, 15:44
I think that at the very least the standard fasm macros should display a warning, or give an error, when it detects that RAX (or EDX for the 32-bit calls) has become invalid.
|
|||
14 Feb 2015, 15:44 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.