Inline asm: move imm to 64-bit register without sign extension

I want to move a 64-bit unsigned integer to a register using inline asm. What happens is a constant that extends the sign if it actually matches 32 bits.

Here is my code:

#include "stdint.h" uint64_t foo() { uint64_t x; asm ("movq %1, %0" : "=q" (x) : "i" (0x00000000faceffff) ); return x; } 

Now clang -S code.c creates the following assembly:

 #APP movq $-87097345, %rax # imm = 0xFFFFFFFFFACEFFFF #NO_APP 

The same goes for gcc. Same thing for movabsq instead of movq . The same goes for the "p" restriction instead of the "i" .

I get the result that I expect if the constant is greater than 32 bits.

+4
source share
1 answer

Is there a suffix for constants to declare them as unsigned long long with gcc? With Microsoft compilers, this is "... ul" in this case 0x00000000faceffffull.

+3
source

All Articles