The MASM Forum

General => The Campus => Topic started by: Pete_80286_Asm on March 29, 2018, 10:07:33 AM

Title: x64 passing parameters by registers or stack
Post by: Pete_80286_Asm on March 29, 2018, 10:07:33 AM
Hi,

Since I'm coding in x64 with ml64 (not using Masm64), I have to use the call command, as there is no invoke command.

I'm passing parameters to my own procs via registers, e.g. rcx, rdx, r8, r9, stack... as you would when calling Windows API calls.
Some people use proc parameters, and pass parameter values via the stack.

Is one better than the other? I've read using registers vs stack in any context, registers is better performance, but in this context is the performance difference negligible?
Does it just come down to personal preference?
Title: Re: x64 passing parameters by registers or stack
Post by: jj2007 on March 29, 2018, 10:50:13 AM
If you are in doubt, time it! But from personal experience, passing it all in registers may be a nanotick faster but it's negligible.
Nonetheless it's a good idea to follow the Windows ABI (first 4 args in regs, rest on stack).

And watch out for alignment and shadow space problems. I like push & pop but there are situations in x64 where it's strictly forbidden, i.e. it will crash your program.
Title: Re: x64 passing parameters by registers or stack
Post by: Pete_80286_Asm on March 29, 2018, 02:40:39 PM
Quote from: jj2007 on March 29, 2018, 10:50:13 AM
Nonetheless it's a good idea to follow the Windows ABI (first 4 args in regs, rest on stack).

Thanks, that's a good call, going with the Microsoft "standard".
Title: Re: x64 passing parameters by registers or stack
Post by: hutch-- on March 29, 2018, 04:35:29 PM
Pete,

Have a look at the reference material for the MASM64 SDK as it has a lot of useful information of how the Microsoft 64 bit ABI and FASTCALL work.
Title: Re: x64 passing parameters by registers or stack
Post by: Pete_80286_Asm on March 29, 2018, 06:31:03 PM
Quote from: hutch-- on March 29, 2018, 04:35:29 PM
Have a look at the reference material for the MASM64 SDK as it has a lot of useful information of how the Microsoft 64 bit ABI and FASTCALL work.

Thanks! Will do!