Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing integer constant to be quadword

Tags:

c

assembly

x86-64

Writing a compiler for class, and no one in the class could figure out exactly why we couldn't do the straight-forward thing.

cmpq %r13, %r10
movq $0, %r10
cmovne $1, %r10

My best guess is that since cmovXX doesn't explicitly define the size of its arguments like movq or movl, $1 doesn't know how big to be, and therefore, throws a type mismatch tantrum.

My question is, how does one force an integer constant to be a quadword? $1q didn't work, so I'm out of guesses.

Thanks!

like image 350
Christopher Wirt Avatar asked Jul 03 '26 04:07

Christopher Wirt


1 Answers

Not really. cmov is simply not available (neither Intel, nor AMD created such an encoding of this particular instruction) with an immediate operand. It operates only on registers and memory locations.

Forcing a particular size of an instruction in AT&T syntax is done by appending one of the size prefixes to the instruction's mnemonic - just the way you have done it.

The only instruction in the x86-64 instruction set that can accept a quadword (64-bit) immediate is the mov instruction with a 64-bit register. However, doing movq $0, %rax will give you the ordinary encoding with a 32-bit immediate. In order to force the assembler to emit a 64-bit immediate, you have to use movabs $0, %rax.

like image 133
Daniel Kamil Kozar Avatar answered Jul 06 '26 12:07

Daniel Kamil Kozar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!