1、main.c
#include <stdio.h>
int test(int
x);
int main
()
{
printf
("调用汇编语言编写的函数test()结果为:%d\n",test(5));
}
2、test.C
.data
.align 16
.text
.global test
# integer
parameters:
rdi,
rsi,
rdx,
rcx,
r8,
r9
# buff
->
rdi
# buffSize
->
rsi
test:
pushq
%rbp
#
push
base
pointer
of
caller
to
stack
movq
%rsp,
%rbp
#
put
stack
pointer
of
caller
to
base
pointer
movq
%rdi,
%rax
#
return
value
should
be
put
in
rax
register
leaveq
#
mov
%rbp,
%rsp
#
pop
%rbp
retq
#
return
3、编译
$ gcc
-o
test
main.c
test.S
4、运行
$ ./test
调用汇编语言编写的函数test()结果为:5
#include
int
int
2、test.C
.data
.align
.text
.global
#
#
#
test:
3、编译
$
4、运行
$
调用汇编语言编写的函数test()结果为:5