这个美元符号在__asm中意味着什么?

时间:2021-05-02 16:58:29

I tried googling this and I couldn't find anything informative enough for my understanding.

我试着在谷歌上搜索一下,但是我找不到任何能让我理解的信息。

int i;
char msg1[] = "odd";
char msg2[] = "even";
char *ptr;
__asm__("                   \
    movl i, %eax\n\
        andl $1, %eax\n\
        jz  zero\n\
        movl $msg1, %eax\n\
        jmp done\n\
zero:\n\
        movl $msg2, %eax\n\
done:\n\
        movl %eax, ptr\n\
  ");

Why does some need $ and the other (such as i) not have a $ sign?

为什么有些人需要美元,而另一些人(比如我)却没有一个美元符号?

3 个解决方案

#1


2  

$1 is constant one

1美元是恒定的

 `andl $1, %eax` this means do  AND of 1 and EAX register.

$ is prefixed infront of contants and immediate valued. msg1 and msg1 are addresses of the two arrays. So they are too prefixed with $.

$是在合同前面加上前缀,立即生效。msg1和msg1是两个数组的地址。所以它们的前缀是$。

i is a c variable. Which is accessed using a memory access (Indirect reference).

我是一个c变量。使用内存访问(间接引用)访问。

Check this reference.

检查这个引用。

#2


1  

Constantsneed to be prefixed with a "$".

君士坦丁需要以“$”为前缀。

movl $msg1, %eax\n\

The dollar sign meant a constant, and the same is true for $msg1. The constant here is the address of msg1.

美元符号表示一个常数,对于$msg1也是如此。这里的常数是msg1的地址。

#3


0  

$ here is same as & in C/C++ meaning address-of

这里的$与&在C/ c++的意思是address-of中相同

#1


2  

$1 is constant one

1美元是恒定的

 `andl $1, %eax` this means do  AND of 1 and EAX register.

$ is prefixed infront of contants and immediate valued. msg1 and msg1 are addresses of the two arrays. So they are too prefixed with $.

$是在合同前面加上前缀,立即生效。msg1和msg1是两个数组的地址。所以它们的前缀是$。

i is a c variable. Which is accessed using a memory access (Indirect reference).

我是一个c变量。使用内存访问(间接引用)访问。

Check this reference.

检查这个引用。

#2


1  

Constantsneed to be prefixed with a "$".

君士坦丁需要以“$”为前缀。

movl $msg1, %eax\n\

The dollar sign meant a constant, and the same is true for $msg1. The constant here is the address of msg1.

美元符号表示一个常数,对于$msg1也是如此。这里的常数是msg1的地址。

#3


0  

$ here is same as & in C/C++ meaning address-of

这里的$与&在C/ c++的意思是address-of中相同