Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

assembly - 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
                          ^~~~~~~~~~~~~~~~~~~
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...