gnu内联汇编语法

没有操作数的汇编程序指令

asm [asm-qualifiers] ( AssemblerInstructions )

拆解说明

  • asm:asm是GNU的汇编扩展
  • asm-qualifiers:限定符,可选volatile、inline
  • AssemblerInstructions:汇编指令,使用引号括起来

具有C表达式操作数的汇编程序指令

  • 使用扩展的asm,您可以从汇编程序读取和写入C变量,并执行从汇编程序代码到C标签的跳转
  • 扩展的asm语法使用冒号(“:”)在汇编程序模板后对操作数参数进行分隔
# 只有输出变量
asm asm-qualifiers ( AssemblerTemplate 
                 : OutputOperands 
                 [ : InputOperands
                 [ : Clobbers ] ])

# 输入变量和输出变量
asm asm-qualifiers ( AssemblerTemplate 
                      : OutputOperands
                      : InputOperands
                      : Clobbers
                      : GotoLabels)

拆解说明

  • OutputOperands:C变量的逗号分隔列表。允许使用空列表。
  • InputOperands:C变量的逗号分隔列表。允许使用空列表。
  • Clobbers:更改的寄存器或其他值的逗号分隔列表,不包括作为输出列出的值。允许使用空列表

输出操作数的约束符号

  • =:变量会被修改
  • +:表示此操作数由指令读取和写入。

Ref

内联汇编语法:https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html
gccindex:https://gcc.gnu.org/onlinedocs/gcc/index.html

posted @ 2024-01-05 12:10  zephyr~  阅读(4)  评论(0编辑  收藏  举报