I have a NASM file and a C file. My OS is Ubuntu 17.04 64 bit
I have followed the instruction from another post. Linking C with NASM
Here's my code
main.c:
#include <stdio.h>
int doit(int a, int b);
int main()
{
printf("%d\n", doit(2,4));
return 0;
}
doit.asm:
global doit
section .data
section .text
doit:
xor rax, rax ;sets rax to 0
mov eax, [rsp+8] ;sets **b** to eax(32bit = int size)
add eax, [rsp+16] ;adds **a** to eax(32bit = int size)
ret
compiling:
home@main:~/Desktop/TEST$ nasm -f elf64 doit.asm && gcc -Wall main.c doit.o
home@main:~/Desktop/TEST$ ./a.out 318503633
home@main:~/Desktop/TEST$
As you can see, The result is not even close to the predicted result, which is 6
Please tell me why is the result different from the 32bit asm