guang@guang-laptop:~/temp/h$ ls
hello hello.o hello.s main.c main.o
!hello.s
.global hello
hello:
movl $4,%eax
movl $1,%ebx
movl $hello,%ecx
movl $30,%edx
int $0x80
.global buff
buff:.ascii "hello world"
as -o hello.o hello.s
extern hello();
int main()
gcc -c main.o main.c
gcc -o hello hello.o main.o
執行結果:
guang@guang-laptop:~/temp/h$ ./hello���ȃ�̀hello wo段錯誤
上面hello.s有兩個bug
.global hello
hello:
push %ebp
mov %esp,%ebp
movl $4,%eax
movl $1,%ebx
movl $buff,%ecx
movl $12,%edx
int $0x80
mov %ebp,%esp
pop %ebp
ret.global buff
buff:.asciz "hello world\n"
ebp,esp由被呼叫函式負責。
這個不會遇到\0就停止,一定讀取edx個字元。
buff反彙編後會變成可執行**,因為在.text段裡
這個例子是沒有引數的。
hello,不是_hello,因為現在的gcc版本較高。若是1.2版的,彙編函式應該是_hello
c程式呼叫彙編函式
c程式呼叫彙編函式 程式例項 按鍵控制led燈 main.c static int printf const char format,int const char format,0xc3e11ad0 void start led key.s define gpm4con 0x110002e0 def...
在C程式中呼叫彙編函式
在趙炯的 linux核心完全剖析 中有乙個在c程式中呼叫彙編函式的介紹 執行as o callee.o callee.s的時候遇到錯誤 callee.s 7 error invalid instruction suffix for push 參考文章 感謝作者 在callee.s中加入 code32...
visual studio中C語言呼叫彙編
在visual studio的c語言開發中,呼叫彙編有幾點需要注意的地方 首先要區別masm和masm32,masm是已經整合在visual studio中的彙編器,即彙編使用的ml.exe,可直接使用對已有的彙編 進行彙編。masm32是一套彙編的sdk,其安裝和配置方法在sabalol的博文 中...