The MASM Forum Archive 2004 to 2012

Project Support Forums => GoAsm Assembler and Tools => Topic started by: Yuri on February 01, 2012, 02:58:27 AM

Title: INVOKE changes flags in x64
Post by: Yuri on February 01, 2012, 02:58:27 AM
Not a big deal, but I thought it might be worth asking. My problem with the x64 invoke is that I am used to signalling success or failure of the called function by clearing or setting the carry flag (got this idea from the manual). But in x64 mode it is no longer possible because GoAsm puts ADD RSP after the call and thereby clears CF. Could this operation be realized using LEA so that the flags were untouched?

LEA is a bit longer code, but if I have to always use RAX for reporting success/failure of the call, I probably lose more than I gain in this respect. Also, zero in RAX is a valid result sometimes, so you have to invent some other failure marker or use another register, and when using this function later, you have to recall how it reports failure. With CF there is nothing to recall.
Title: Re: INVOKE changes flags in x64
Post by: qWord on February 01, 2012, 09:57:37 AM
hi,
you can also use rcx,rdx,r8,r9,r10 and r11 for returning information about functions result.(?)
Title: Re: INVOKE changes flags in x64
Post by: Yuri on February 01, 2012, 10:51:11 AM
Hi, qWord

Yes, I can, but using the carry flag seems much simpler and I am used to it already. Recently I was converting a couple of my 32-bit programs to switchable x86/x64 code and I had to go through all the functions to change the way they reported success and failure, and also through all the places where they were called. I couldn't say I liked that. The CF method seems much more convenient and unambiguous.

Actually in switchable code I can't use the new registers (r8, etc), and I already use R/ECX and R/EDX for returning additional data from some functions. So I can't restrict one of them to the role that CF used to play.
Title: Re: INVOKE changes flags in x64
Post by: dedndave on February 01, 2012, 03:10:10 PM
LEA sounds like the way to go   :U
Title: Re: INVOKE changes flags in x64
Post by: donkey on February 01, 2012, 05:36:50 PM
I agree that LEA should be used in this case, it will also make the FLAGS keyword useful once again (USES FLAGS is not effective with the X64 invoke).

Edgar
Title: Re: INVOKE changes flags in x64
Post by: wjr on February 12, 2012, 11:04:19 PM
I have forwarded the LEA revision of INVOKE to Jeremy to be incorporated into the upcoming GoAsm Version 0.57.
Title: Re: INVOKE changes flags in x64
Post by: Yuri on February 13, 2012, 01:38:39 AM
Thanks, Wayne. It's great GoAsm is under development again. :8)