Below is the C code for example.
long example(long* p, long i)
{
long t = *p + i;
*p = t;
return t;
}
Equivalent assembly code that is compatible with IA32 machine is presented below.
example:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %edx
movl 12(%ebp), %eax
addl (%edx), %eax
movl %eax, (%edx)
popl %ebp
ret
While the x86-64 version is following.
example:
movq %rsi, %rax
addq (%rdi), %rax
movq %rax, (%rdi)
ret
We can see there are some differences between the two fragments of code, including:
- Instead of movl and addl instructions, we see movq and addq. The pointers and variables declared as long integers are now 64 bits rather than 32 bits.
- We see the 64-bit versions of registers. The procedure returns a value by storing it in register %rax.
- No stack frame gets generated in the x86-64 version. This eliminates the instructions that set up and remove the stack frame in IA32 code.
- Arguments p and i are passed in registers rather than on the stack. This eliminates the need to fetch the arguments from memory.