我试图引用注册文字;我需要这个,因为我想使用像mulx
这样的指令,要求其中一个输入位于rdx
。
我试过这个:
#include <stdint.h>
int main() {
uint64_t x = 15, y = 3, z, w;
asm ("mov %[x], rdx\t\n"
"mulx %[y], %[z], %[w]\t\n"
: [z] "=&r" (z), [w] "=&r" (w)
: [x] "r" (x), [y] "r" (y)
: "rdx"
);
return z + w;
}
仅适用于-masm=intel
,否则会提供
$ gcc foo.c /tmp/ccGealWM.o: In function `main': foo.c:(.text+0x20): undefined reference to `rdx' collect2: error: ld returned 1 exit status
我已经尝试了
#include <stdint.h>
int main() {
uint64_t x = 15, y = 3, z, w;
asm ("mov %[x], %rdx\t\n"
"mulx %[y], %[z], %[w]\t\n"
: [z] "=&r" (z), [w] "=&r" (w)
: [x] "r" (x), [y] "r" (y)
: "rdx"
);
return z + w;
}
给出了
$ gcc foo.c foo.c: In function ‘main’: foo.c:5:7: error: invalid 'asm': operand number missing after %-letter asm ("mov %[x], %rdx\t\n" ^