问题
I'm trying to write my first assembly function to be called from a C program. Here is the .c part:
#include <stdio.h>
extern int sum(int a, int b);
int main() {
printf("2+3 = %d\n", sum(2,3));
return 0;
}
And the assembly part:
.text
.global sum
sum:
push %rbp
mov %rsp, %rbp
mov 8(%rbp), %rax
add 12(%rbp), %rax
pop %rbp
ret
According to some tutorials, arguments should be stored in %ebp (in 32bit version) register. However, when I compile the code above, I'm getting this result:
2+3 = 4195607
Could someone explain me what am I doing wrong?
Oh, and here is the Makefile:
test: test.o testc.o
gcc -o test test.o testc.o
test.o: f1.s
gcc -o test.o -c f1.s
testc.o: f2.c
gcc -c -o test.o f2.c
Thank you in advance for any tips!
Regards, Filip
来源:https://stackoverflow.com/questions/22917922/passing-arguments-from-c-to-64bit-linux-assembly