linux中c語言常用內嵌彙編

2021-08-15 01:45:02 字數 2904 閱讀 6567

原始碼位址
//

// main2.c

// allen

//// created by allenboy on 2018/1/20.

////編譯不過 可以生成.s檔案 gcc -s main2.cpp

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3)

#include int a = 10;

int b = 20;

int result;

int main()

//  allen

//// created by allenboy on 2018/1/20.

////編譯能過 可以生成可執行檔案 gcc main2.cpp (a.out) 或者 gcc -o test main2.cpp (test) 運動時用 ./a.out(./test)

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3)

#includeint main()

//  allen

//// created by allenboy on 2018/1/20.

////

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3)

//tset 3

#include int main ()

; char* output[30];

int length = 25;

asm volatile (

"cld \n\t"

"rep movsb"

::"s"(input),"d"(output),"c"(length)

); //movs指令需要的3個指令,s代表要複製的字串位址(esi) d代表目標位置存放在edi c 要複製的長度放在 ecx

printf("%s",*output);

return 0;

}

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset 4佔位暫存器 表示法

#include int main ()

# 9 "testasm.c" 1

imull %eax,%edx

movl %edx,%eax

# 0 "" 2

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset 5當輸入輸出是同乙個變數時可以用相同暫存器

#include int main ()

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset 6替換佔位符

#include int main ()

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset 7使用記憶體位置

#include int main ()

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset 8浮點數求法

#include int main ()

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset 9浮點數求法

#include int main ()

# 9 "testasm.c" 1

fsincos

# 0 "" 2

fxch %st(1)

fstps -20(%rbp)

fstps -8(%rbp)

movss -20(%rbp), %xmm5

movss %xmm5, -4(%rbp)

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset 10跳轉

#include int main ()

movl -8(%rbp), %edx

# 9 "testasm.c" 1

cmp %eax,%edx

jge greater

movl %eax,%eax

jmp end

greater:

movl %edx,%eax

end:

# 0 "" 2

movl %eax, -4(%rbp)

// gcc version 7.2.0 (ubuntu 7.2.0-8ubuntu3) 

//tset11 跳轉 數字加字母f

#include int main ()

movl $20, -8(%rbp)

movl -12(%rbp), %eax

movl -8(%rbp), %edx

# 9 "testasm.c" 1

cmp %eax,%edx

jge 0f

movl %eax,%eax

jmp 1f

0: movl %edx,%eax

1:# 0 "" 2

movl %eax, -4(%rbp)

movl -4(%rbp), %eax

movl %eax, %esi

Linux系統呼叫(C內嵌彙編)

linux下對檔案操作有兩種方式 系統呼叫 systemcall 和庫函式呼叫 library functions 可以參考 linux程式設計 英文原版為 beginning linuxprogramming 作者是neil matthew和richard stones 第三章 working w...

Linux系統呼叫(C內嵌彙編)

linux下對檔案操作有兩種方式 系統呼叫 systemcall 和庫函式呼叫 library functions 可以參考 linux程式設計 英文原版為 beginning linuxprogramming 作者是neil matthew和richard stones 第三章 working w...

GCC中的內嵌組合語言

一.宣告 雖然linux的核心 大部分是用c語言編寫的,但是不可避免的其中還是有一部分是用組合語言寫成的。有些組合語言 是直接寫在彙編源程式中的,特別是linux的啟動 部分 還有一些則是利用gcc的內嵌組合語言嵌在c語言程式中的。這篇文章簡單介紹了gcc中的內嵌式組合語言,主要想幫助那些才開始閱讀...