zoukankan      html  css  js  c++  java
  • Linux 下C与汇编交互的小例子

    原文地址:http://www.cnblogs.com/jjyjjyjjy/archive/2011/04/23/2024828.html

     

     

          C code:

        #include <stdio.h>

            extern add(int,int);

        int main(int argc,char **argv)

        {

          int result = add(4,5);

          printf("result:%d\n",result);

        }

        

           assembly code:

        ;nasm -f elf add.s -o add.o

        [section .data]

          Message db "calcuated result:%d",0xa,0

        [section .text]

          extern printf ;invoke c library

          global add

        add:

          mov eax,[esp+4];

          add  eax,[esp+8];

          

          mov ebx,eax;

          push eax;

          push dword Message;

          call printf;

          add esp,8;

          mov eax,ebx;

          ret;

    编译命令:

        nasm -f elf -o add.o add.s

            gcc -c testAdd.c -o testAdd.o

        gcc -o test_add testAdd.o add.o

        ./test_add 

  • 相关阅读:
    flex
    导航守卫 -vue
    H5 History
    JSX -react
    插槽slot -vue
    js 模拟鼠标绘制方块
    js 模拟滚动条
    js 实现简易留言板功能
    js 实现端口列表话
    js 为数组编写该方法;indexOf
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2280271.html
Copyright © 2011-2022 走看看