0

I saw movw %dx (%eax) on my textbook, and I'm wondering why use movw rather than movswl or movzwl here?

I think that there are 2 bytes in %dx and 4 bytes in (%eax) (for a 32-bit machine), so it needs an extension?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 3
    `(%eax)` has no implied size. This instruction writes 2 bytes. If you wanted to write 4, you could use extension. Note that neither `movsx` nor `movzx` allow for a memory destination. – Jester Aug 06 '20 at 18:51
  • A 32-bit x86 can never do a 64-bit (8-byte) store with scalar integer registers in one instruction, except with `cmpxchg8b`. You'd need x86-64 to be able to `mov %rdx, (%rax)` (aka `movq`), or in 32-bit use `movsd %xmm0, (%eax)` to store the low half of a vector register. – Peter Cordes Aug 06 '20 at 18:58
  • @PeterCordes oh I'm sorry! I mean 4 bytes actually~ Thanks~ – MusicalChicken Aug 06 '20 at 19:01
  • Ok, then see Jester's comment. x86 doesn't have any instructions that extend a register *and* store it to memory. If you want to store 4 bytes to memory at the address from EAX, `movswl %dx, %edx` / `mov %edx, (%eax)`. – Peter Cordes Aug 06 '20 at 19:01
  • @PeterCordes I see! Thanks your explanation~ – MusicalChicken Aug 06 '20 at 19:07

0 Answers0