歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 如何在64位的Linux系統上使用匯編和C語言混合編程

如何在64位的Linux系統上使用匯編和C語言混合編程

日期:2017/3/1 10:05:38   编辑:Linux編程

最近在看於淵的一個操作系統的實現,在第五章的時候匯編和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;
}

Copyright © Linux教程網 All Rights Reserved