Home

ModRM

ModRM is a byte used in x86 instruction encoding to specify operand locations and addressing modes. It is part of many instructions that operate on memory or on registers, and is often followed by displacement bytes and, when present, a scale-index-base (SIB) byte. The ModRM byte encodes three fields: mod, reg/opcode, and r/m.

The reg/opcode field can designate a register operand. In some instructions it also serves as an opcode

The mod field selects the addressing mode and displacement size. In general, mod=11 means both operands are

The r/m field selects the memory address or a register operand. When r/m=100, a SIB byte follows

ModRM is a core element of many instructions across 16, 32, and 64-bit modes, functioning as both

extension,
selecting
an
operation
or
sub-operation
when
the
main
opcode
requires
additional
bits.
registers.
For
memory
operands,
mod=00,
01,
or
10
indicate
no
displacement,
8-bit
displacement,
or
32-bit
displacement
respectively
(with
exceptions
in
certain
r/m
cases).
In
32-
and
64-bit
modes,
r/m
values
determine
the
memory
operand
or
a
special
case
such
as
absolute
or
RIP-relative
addressing.
In
64-bit
mode,
mod=00
and
r/m=101
encodes
a
RIP-relative
disp32
address
rather
than
a
simple
absolute
address,
while
mod
values
with
other
r/m
values
produce
standard
memory
operands
or
require
a
SIB
byte
when
r/m=100.
to
specify
a
scalable
index
and
base,
with
fields
scale
(2
bits),
index
(3
bits),
and
base
(3
bits).
The
effective
address
is
computed
from
base
+
index*scale
+
displacement,
with
several
special
cases
for
absent
index
or
base
values
and
for
displacement
size
dictated
by
mod.
a
register
selector
and
a
memory
addressing
descriptor,
often
in
conjunction
with
SIB
encoding.