News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

x64 passing parameters by registers or stack

Started by Pete 80286, March 29, 2018, 10:07:33 AM

Previous topic - Next topic

Pete 80286

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?

jj2007

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.

Pete 80286

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".

hutch--

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.

Pete 80286

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!