1

enter image description here

The answer is 1. movl 2. movw 3. movb 4. movb 5. movq 6. movw

But how do we determine that?

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Joshua Leung
  • 2,219
  • 7
  • 29
  • 52

1 Answers1

1

Simply look at the destination operand and specify its size.

Case 1 : You are moving the value at address specified by register rsp to the register eax. Therefore, you should use movl which means move a long value. This is done because the eax register is 4 bytes wide which make up a long.

The same applies to the other cases.

  • movb - move byte.
  • movw - move word (2 bytes).
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
preciousbetine
  • 2,959
  • 3
  • 13
  • 29
  • 1
    This is true, although as harold points out GNU assembler doesn't require any instruction suffixes in the cases presented in the OPs question because it will look at the operands to see if the size can be implied. One situation where the assembler can't make such a determination is for something like `mov $0xff, (%rcx)` . It doesn't know how many bytes need to be written to memory location pointed to by RCX. Is 0xff a byte, word, dword? You have to be explicit by using `movb $0xff, (%rcx)`, `movw $0xff, (%rcx)`, `movl $0xff, (%rcx)` etc. – Michael Petch Sep 14 '19 at 18:18
  • Your rule fails for the last case: storing a register to memory. The operand-size can be implied by either operand for pretty much any instruction (except `movzx` / `movsx`, aka AT&T `movzw` / `movzb` / etc where only the destination can imply the operand size, because the source can have a different size. e.g. `movswl (%rax), %ecx` can be written as `movsw (%rax), %ecx`) – Peter Cordes Sep 17 '19 at 03:06
  • 1
    > *You are moving the value at address specified by register rsp to the register eax.* It is the other way around. rsp is the dest, and eax is source. – Waqar Aug 02 '20 at 09:21
  • Same question here, with a better answer imo: https://stackoverflow.com/a/20248163/2279422 – Waqar Aug 02 '20 at 09:21