Jump to content

ModR/M

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 109.70.40.55 (talk) at 02:11, 21 March 2022. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The ModR/M byte is an important part of instruction encoding for the x86 instruction set.

Description

Opcodes in x86 are generally one-byte, though two-byte instructions and prefixes exist. ModR/M is the byte following the opcode and adds additional information for how the instruction is executed.[1]: §2.1  The format is:

Bit 7 6 5 4 3 2 1 0
Usage MOD REG R/M

where REG specifies a register and R/M may contain a register or specify an addressing mode, depending upon the value of MOD.

Some instructions cannot make use of the REG portion of the ModR/M byte. Many of these instructions are "multiplexed" using this field, where a single opcode can refer to multiple instructions, and the REG field determines the instruction. In opcode listings, these are specified by following the opcode with a slash (/) and a digit 0-7.[1]: §3.1.1.1 

64-bit changes

The ModR/M byte is central to the changes introduced with AMD's 64-bit extension to the original instruction set. In long mode, any opcode whose highest four bits are 0100 (decimal 4) are considered to be a new prefix, the REX prefix.[2]: §1.2.7  The lowest four bits of the prefix byte serve various purposes, including an extra bit for the REG and R/M fields of the ModR/M byte that follows. Among other changes, expanding these values from three bits to four doubles the number of available processor registers from eight to sixteen.[2]: §1.4 

References

  1. ^ a b Intel Coropration (2016-09-01). "Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 2A". Retrieved 2021-09-13.
  2. ^ a b Advanced Micro Devices (2021-03-01). "AMD64 Architecture Programmer's Manual Volume 3: General-Purpose and System Instructions" (PDF). Retrieved 2021-09-13.

See also