gcc提供了內嵌語法,使在 C
語言中可以直接撰寫組合語言。
asm
voltaile( ;
內嵌起始符號
assembler template ; 組合語言程式
: output operands ; : 輸出參數列表
: input operands ; : 輸入參數列表
: list of clobbered registers ; : 被更改的暫存器列表
);
":" : 分隔符號
assembler template: 組語部分,需存取output/input operands列表內容
%0: 輸出
%1~N:輸入
clobber: 告訴compiler,哪些register被這段code改了
operand register的修飾符(constraint):
- f : 是floating
point register (有些 cpu 有專屬的 floating point
register)
- I : 立即定址 immediate
operands
- J :
Indexing constants
- K :
negative value in rhs
- L:
negative value in rhs
- M : for
shift
- r :
General registers -- ARM 一般用這個
- = :
Write-only (通常所有的 output operand 都會加這個符號)
- + :
Read-Write (inline assemnly 不支援這個符號)
- & :
Output only - 這個register 只做 output 使用
參考:
http://stenlyho.blogspot.tw/2008/08/cinline-casmasm-code-asmmovl-1eaxnt.html