zoukankan      html  css  js  c++  java
  • 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

    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205230454941-1401739817.jpg)

    (2)用汇编语言实现函数

    1.获取CPU寄存器

    s.s
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205230615359-318359246.png)

    hello.c
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205230827138-1221625878.png)

    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

    编译运行截图

    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205231019591-1693628239.jpg)

    ## 2.用汇编语言编写sum()函数 ##
    mysum.s
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205231327139-650306971.png)

    main.c
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205231501911-1548366792.png)

    makefile
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205231606102-2013266619.png)
    编译运行截图:
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205231056476-151029161.jpg)

    3.从汇编中调用C函数
    sub.s sub,c
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205231815964-806755724.png)

    编译运行截图:
    ![](https://img2020.cnblogs.com/blog/1812365/202112/1812365-20211205231108805-2113786860.jpg)

  • 相关阅读:
    Windows server 2008 R2远程桌面终端连接数的破解
    VirtualBox是什么
    蓝屏代码和解决办法
    最新版都叫兽数据恢复软件和注册机
    两种颜色混合
    [译]GLUT教程
    OpenGl的glMatrixMode()函数理解
    OpenGL ES 画直线代码实例
    7天学习opengl入门
    error C2275 将此类型用作表达式非法
  • 原文地址:https://www.cnblogs.com/kuohao1214/p/15647214.html
Copyright © 2011-2022 走看看