NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: nobody on June 01, 2009, 03:41:35 PM

Title: 64 Bit: how to call function from C?
Post by: nobody on June 01, 2009, 03:41:35 PM
Hi,
can someone help me with an example, of how to call a function made in assembly from C language for 64 bit? (using gcc under linux)
I basically need to pass the 2 pointers to the function and i would like to pass them through the registers. What registers should i use? And how do i tell GCC i want the data in those registers? And also, where should i store return value?

Thanks in advance
Title: Re: 64 Bit: how to call function from C?
Post by: BioTube on June 19, 2009, 02:18:30 AM
Luckily, passing on the registers is standard in long mode. The preserved registers are rbp, rbx and r12 - r15; integers are passed on, in order, rdi, rsi, rdx, rcx, r8 and r9(any extras are, of course, passed on the stack). Return the first 64 bits in rax and the second 64 in rdx. You can find out more about the ABI here:

http://www.x86-64.org/documentation/abi-0.99.pdf (http://www.x86-64.org/documentation/abi-0.99.pdf)
Title: Re: 64 Bit: how to call function from C?
Post by: nobody on June 19, 2009, 03:16:28 AM
When i went looking I found that linux and microsoft had different standards... and that one points to AMD - is there also an intel ABI (there seems to be a hint of linux-ia64 as opposed to linux-x86_64


(sorry I searched some for the links I found, I vaguely remember they were referenced on wikipedia, I might be wrong)
Title: Re: 64 Bit: how to call function from C?
Post by: Zdenek Sojka on June 21, 2009, 10:59:25 PM
x86_64 covers both AMD64 and EM64T (Intel's implementation of AMD64)

You want IA-64 docs only if you have Itanium processor.