Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: operand size mismatch for `movq'

I'm trying to compile the following assembly...

movq $0x3534373536383235, 0x000000000055638f8
movq $0x55638f8, %rdi
retq

The first line throws the error Error: operand size mismatch for 'movq'

Which doesn't make sense to me, because they are both 8 byte numbers.

I did a little research and movabsq was recommended, like so...

movabsq $0x3534373536383235, 0x000000000055638f8
movq $0x55638f8, %rdi
retq

But this throws the error: Error: operand size mismatch for 'movabs'

What am I missing?

Here's the entire error from my mac

level3.s:1:27: error: invalid operand for instruction
movq $0x3534373536383235, 0x000000000055638f8
                          ^~~~~~~~~~~~~~~~~~~
like image 318
Kendall Weihe Avatar asked Dec 18 '22 12:12

Kendall Weihe


1 Answers

If you look in the manual under the lemma MOV (which is, admittedly, a bit intimidating), you will find that there is no mov r/m64, imm64.

There's a way to load a full 64bit constant into a register, and there's a way to load a sign-extended 32bit constant into a 64bit memory location, but there is no single instruction that takes a 64bit immediate and writes it to memory.

So you have to do it in two steps, such as by using a temporary register or by writing two dwords straight to memory separately.

like image 118
harold Avatar answered Jan 02 '23 06:01

harold