问题
I am trying to go from a C function to a function with inline-asm to a standalone function in an assembly file. Here is what I have so far:
#include <stdio.h>
int add_five(int n)
{
n = n + 5;
return n;
}
int add_five_inline(int n)
{
asm("lea 5(%1), %0" : "=r" (n) : "r" (n));
return n;
}
int main(void)
{
int a=add_five(7);
int b=add_five_inline(8);
// int c=add_five_asm(9); // <-- here
printf("7+5=%d | 8+5=%d\n", a, b);
}
7+5=12 | 8+5=13
What is the process to take something like the following asm and call it from a C function?
# file.s
add_five_asm:
lea 5(%rdi), %rax
ret
How would I call and compile so that I can call that asm
function 'as-if' it were a normal C function?
来源:https://stackoverflow.com/questions/65837016/how-to-call-a-function-in-an-external-assembly-file