开发者

What does this dollar sign mean in __asm?

开发者 https://www.devze.com 2023-02-18 17:59 出处:网络
I tried googling this and I couldn\'t find anything informative enough for my understanding. int i; char msg1[] = \"odd\";

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 oth开发者_如何学编程er (such as i) not have a $ sign?


$1 is constant one

 `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 $.

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

Check this reference.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消