GNU Assembly Inline:%1和%0是什么意思? [英] GNU assembly Inline: what do %1 and %0 mean?

查看:63
本文介绍了GNU Assembly Inline:%1和%0是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对GNU程序集内联非常陌生,我读过多次文章,但仍然不完全了解发生了什么.据我了解:

I am very new to GNU assembly inlining, I have read multiple write ups but still do not fully understand what is going on. From my understanding:

移动%eax,%ebx \ n \ t 会将%eax 中的内容移动到 ebx 中,但不会添加内容彼此

movl %eax, %ebx\n\t will move whatever is in %eax into ebx, but will not add the contents to each other

addl%eax,%ebx \ n \ t 将使用 ebx 添加%eax 的内容,并将其保持在最右边注册

addl %eax, %ebx\n\t will add the contents of %eax with ebx and keep it at the right most register

addl%1,%0 \ n \ t 这是我感到困惑的地方,我们要添加1和0?为什么我们需要在那里有%0 ?

addl %1, %0\n\t this is where i get confused, we are adding 1 and 0? why do we need to have the %0 there?

推荐答案

整个asm内联代码块如下:

The whole asm inline block looks like:

 asm [volatile] ( AssemblerTemplate
                      : OutputOperands
                      [ : InputOperands
                      [ : Clobbers ] ])

OR

 asm [volatile] ( AssemblerTemplate
                      : OutputOperands)

在AssemblerTemplate中是您的汇编代码,在Output/InputOperands中,可以在C和ASM之间传递变量.

In the AssemblerTemplate is your assembly code, and in Output/InputOperands, you can pass variable between C and ASM.

然后在Asm中,%0表示将第一个变量作为OutputOperand或InputOperand传递,将%1传递给第二个变量,依此类推.

Then in Asm, %0 refers to the first variable passed as OutputOperand or InputOperand, %1 to the second, etc.

示例:

 int32_t a = 10;
 int32_t b;
 asm volatile ("movl %1, %0" : "=r"(b) : "r"(a) : );

此asm代码等效于"b = a;"

This asm code is equivalent to "b = a;"

更详细的解释在这里: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

A more detailed explanation is here: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

这篇关于GNU Assembly Inline:%1和%0是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆