c語言呼叫彙編的方法

2022-09-29 11:57:13 字數 1081 閱讀 9243

c部分很簡單,檔名隨便,如main.c:

複製** **如下:

#include

#include

void dectobin(long dec,char *b); //宣告外部彙編函式

int main()

本人使用的是mac 64位系統,所以64bit暫存器為r開頭,如:kmabupbrax、rbx等。

c呼叫的**如下,儲存的檔名隨便,如decbin.s or decbin.s.

複製** **如下:

.global _dectobin #下劃線是必須的

_dectowww.cppcns.combin:

pushq     %rbp

movq    %rsp,%rbp

movq     %rdi,-8(%rbp) #第乙個引數

movq     %rsi,-16(%rbp) #第二個引數

movq    -8(%rbp),%rax

movq    -16(%rbp),%rbx

movq    $63,%rcx

a:    rclq     $1,%rax

jnc    b

movb     $49,(%rbx)

&nbs程式設計客棧p;   jmp c

b:    movb     $48,(%rbx)

c:    addq    $1,%rbx

loop a

popq     %rbp

retat&t語法的彙編網上有很多,俺就不介紹了。

在mac中使用的實際是clang編譯器,這又牽扯到了llvm專案,llvm是構架編譯器(compiler)的框架系統,apple是llvm計畫的主要資助者。

cc鏈結的就是clang,makefle檔案:

複製** **如下:

main:main.o decbin.o

main.o:main.c

decbin.o:decbin.s

cc -c $<

clean:

-rm main.o decbin.o main

本文標題: c語言呼叫彙編的方法

本文位址:

visual studio中C語言呼叫彙編

在visual studio的c語言開發中,呼叫彙編有幾點需要注意的地方 首先要區別masm和masm32,masm是已經整合在visual studio中的彙編器,即彙編使用的ml.exe,可直接使用對已有的彙編 進行彙編。masm32是一套彙編的sdk,其安裝和配置方法在sabalol的博文 中...

c呼叫彙編函式 1

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 ...

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...