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.
Constants
need 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
精彩评论