手机版
你好,游客 登录 注册
背景:
阅读新闻

如何在64位的Linux系统上使用汇编和C语言混合编程

[日期:2012-12-11] 来源:Linux社区  作者:chenchenluo [字体:大 中 小]

最近在看于渊的一个操作系统的实现,在第五章的时候汇编和C 同时使用时碰到了问题:代码如下

foo.s

 extern choose
 
 ;;;;;the data area
 num1st            dd        3
 num2nd        dd        4
 
 global        _start
 global        myprint
 
 
 _start:
 
    push        dword [num1st]
    push        dword [num2nd]
 
    call    choose
    add        esp,8
 
    mov        ebx,0
    mov        eax,1
    int        0x80
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;; function protype    :void myprint(char *msg, int len)
    ;;;; display the message
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 myprint:
     
    mov        ecx,[esp+4]
    mov        edx,[esp+8]
    ;mov        edx,esi
    ;mov        ecx,edi
 
    mov        ebx,1
    mov        eax,4
    int        0x80
    ret 

bar.c

 /************  bar.c *****************/
 
 void myprint(char *msg,int len);
 
 int choose(int a,int b)
 {
    if (a>=b) {
        myprint("the 1st one\n",13);
    }
 
    else {
        myprint("the 2st one\n",13);
    }
 
    return 0;
 }

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款