1
votes

I am using an assembly code in a C function. But gcc gives unsupported instruction 'mov' error for the following code:

uint32_t faulting_address;
asm volatile("mov %%cr2, %0" : "=r" (faulting_address));  

I don't understand what is wrong with this.

1
GCC's inline assembly uses AT&T syntax. - user3920237
Thank you, I tried asm volatile("movl $0, %%cr2" : "=r" (faulting_address)) but nothing changes. - user2972185

1 Answers

1
votes

The syntax is correct, but the error is more than likely because you're compiling for a 64-bit target, in which case the mov needs to be 64 bits. Just change faulting_address to a uint64_t and it will compile.

Alternatively, if you want it to be 32 bits, you'll need to use -m32 or other similar option to compile for a 32-bit target.