歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux C語言調用匯編

Linux C語言調用匯編

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

Linux內核裡面和一些開源的代碼裡,我們經常看到一些內聯匯編(inline assemble)函數。裡面經常有一些匯編代碼

下面的函數不是內聯匯編,是一個C語言調用AT&T匯編 (還有一種Intel匯編)

int replace(){

int a=1;

int b=2;

asm("movl %1,%%eax"
"movl %%eax,%0"

: "=r" (b) /* output Regester */

: "r" (a) /* input Regester */

: "%eax"); /* eax Regester */

printf(" b is %d \n",b)

}

調用replace輸出結果:
b is 1

Copyright © Linux教程網 All Rights Reserved