2.5 OpenEuler 中C与汇编的混合编程
在X86_64架构下实践2.5中的内容:
## 1.在Ubuntu系统下实践2.5中的内容 ##
(1)将C代码编译成汇编代码
代码如下:a.c
#include<stdio.h>
extern int B();
int A(int x,int y)
{
int d,e,f;
d=4;e=5;f=6;
f=B(d,e);
}
汇编代码如下:a.s

(2)用汇编语言实现函数
1.获取CPU寄存器
s.s

hello.c

makefile
hello:hello.o s.o
gcc -o hello hello.o s.o
hello.o:hello.c
gcc -c hello.c
s.o:s.s
gcc -c s.s
clean:
rm hello hello.o s.o
编译运行截图

## 2.用汇编语言编写sum()函数 ##
mysum.s

main.c

makefile

编译运行截图:

3.从汇编中调用C函数
sub.s sub,c

编译运行截图:


浙公网安备 33010602011771号