1

So I have a bit of assembly I got by doing objdump on a binary given to me. It has the following line

movabs $0xcccccccccccccccd,%rdx

I modeled my own assembly after this and got an error.

I am trying to write my own assembly file and turn it into an object so that I can get the byte code for the assembly. Unfortunately every time I try to compile with gcc -c code.s I get the following message Error: operand size mismatch formovabs'` which confuses me as I literally modeled my assembly after other assembly code on my machine.

Here is the assembly:

movq 0x602308,%rdx
movabs $0x4d0ddd6dddd95b2g,(%rdi)

Essentially I am trying to set the value at address 0x602308 to the constant in line 2.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
J.Doe
  • 1,502
  • 13
  • 47
  • Possible duplicate of [Error: operand size mismatch for \`movq'](https://stackoverflow.com/q/40032148/608639) and [movq and 64 bit numbers](https://stackoverflow.com/q/19582654/608639). – jww Feb 15 '18 at 04:56
  • 1
    If you want to set value at `0x602308`, you better use that `rdx`, not `rdi`. And hexadecimal digit `g` may cause the compiler to object... Based on those duplicates it looks to me the best solution is to use: `mov $imm32_bottom32, 0x602308` `mov $imm32_top32, 0x602308+4`. – Ped7g Feb 15 '18 at 05:29
  • 2
    @Ped7g: if you have a spare register, use `movabs $imm64, %rdx` / `mov %rdx, 0x602308`. That avoids store-forwarding stalls if an 8-byte load wants the value, and is more compact (especially when the addressing mode isn't a compact one like `(%rdi)`, you don't want to repeat the absolute address twice in the machine code.) – Peter Cordes Feb 15 '18 at 05:55

0 Answers0