在 2024/1/6 0:30, David Brown via Gcc-help 写道: > I'd imagine that the "X" operand doesn't see much use in real inline assembly - on x86 and ARM the > assembly instruction template would usually depend on where the data is put.  But if anyone can > explain this behaviour to me, I am very curious to know what is going on. I haven't used it at all and know nothing about its original intention. From GCC documentation, it looks like `X` specifies that the argument is allowed to be passed via either a register or memory, so it should be eligible for overloaded mnemonics, such as the MOV, FLD and ADDPD instructions on x86. For example, given (https://gcc.godbolt.org/z/vxb1aTe9c) ``` static int value; int test_X(void) { int a; __asm__("mov %0, %1" : "=&r"(a), "+X"(value)); return a; } ``` GCC passes `value` directly via memory ``` test_X: mov eax, DWORD PTR value[rip] ret ``` and Clang passes it via the ECX register ``` test_X: mov ecx, dword ptr [rip + value] mov eax, ecx mov dword ptr [rip + value], ecx ret ``` If `static int value;` is changed to `extern int value;` then GCC will reject it, as the operand no longer fits into a single operand; but the clang approach still works, with `value` replaced with `value@GOTPCREL`. It doesn't seem very useful for RISC machines. -- Best regards, LIU Hao