首页 / 操作系统 / Linux / 如何在64位的Linux系统上使用汇编和C语言混合编程
最近在看于渊的一个操作系统的实现,在第五章的时候汇编和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
",13); } else { myprint("the 2st one
",13); } return 0; }
收藏该网址