0

In the MOD part of the MOD_RM byte, it has four values for what the mode can be:

  • 11 - Uses a register
  • 10 - 32-bit displacement
  • 01 - 8-bit displacement

From here: http://www.c-jump.com/CIS77/CPU/x86/X77_0060_mod_reg_r_m_byte.htm

The examples it gives are:

MOD R/M Addressing Mode
=== === ================================
 00 000 [ eax ]
 01 000 [ eax + disp8 ]               (1)
 10 000 [ eax + disp32 ]

I'm not quite sure I understand the difference between a 32-bit and 8-bit displacement. What would the following be examples of?

# sorry this is using ATT syntax not Intel
movb $1, (%eax)
movw $1, 2(%eax)
movl $1, (%eax, %eax)
movq $1, 2(%eax, %eax)
movq $1, 2(%eax, %eax)
movq $1, 2(%rax, %rdi)
movq $1, 2(%rax, %rdi, 4)

is 32- and 8-bit the size of the second register used in the memory address? If so, why does it not include a 16- or 64- bit displacement in the MOD ?

samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
  • They'd be examples of errors. Did you even try assembling your example? `(%eax, %al)` is not encodeable in any mode. All registers in an addressing mode have to be the same size, and that size has to be 32 or 64 (in 64-bit code), or 16 or 32 in 16 or 32-bit code. (Address-size prefix toggles to the non-default size). Also, all of them are missing an operand-size suffix, so it's ambiguous with an immediate source and a memory destination. – Peter Cordes Oct 09 '20 at 07:03
  • @PeterCordes just updated it and verified it assembled. – samuelbrody1249 Oct 09 '20 at 07:10
  • Ok. Anyway no, the displacement part of an address is the constant part, like an immediate. In all of yours it's either empty or `2`, which fits in a disp8. Look at the machine code (e.g. with `objdump -d`) and notice which parts of the source end up in bytes of code, and that there are 3 bytes of high zeros. Unless you use a `{disp32}` GAS override like mentioned in [x86 XOR opcode differences](https://stackoverflow.com/q/50336269) that I linked in an answer to one of your previous questions. https://sourceware.org/binutils/docs/as/i386_002dMnemonics.html – Peter Cordes Oct 09 '20 at 07:11
  • [x64 instruction encoding and the ModRM byte](https://stackoverflow.com/a/15511698) quotes a table from the Intel manuals with footnotes that somewhat clarify what displacements are. – Peter Cordes Oct 09 '20 at 07:14

0 Answers0