Logo
Articles Compilers Libraries Books MiniBooklets Assembly C++ Rust Go Linux CPU Others Videos
Advertisement

Article by Ayman Alheraki on January 11 2026 10:37 AM

x86-64 Machine Code Encoding SIB Byte Structure and Use Cases

x86-64 Machine Code Encoding: SIB Byte Structure and Use Cases

The Scale-Index-Base (SIB) byte is an essential extension of the ModR/M byte in x86-64 instruction encoding, enabling complex memory addressing modes beyond simple base register addressing. The SIB byte allows combinations of scaled index registers and base registers, providing powerful addressing flexibility needed for high-performance and complex software implementations.

1. Purpose of the SIB Byte

The SIB byte follows the ModR/M byte when the R/M field of the ModR/M byte is set to 100 (binary), indicating that a SIB byte is required to fully specify the effective address. It provides three components:

  • Scale factor to multiply the index register

  • Index register to provide scaled offset

  • Base register to provide the starting point of the memory address

Together, these fields allow addressing of memory using the formula:

Effective Address = Base + (Index × Scale) + Displacement

This is critical for supporting array indexing, pointer arithmetic, and complex data structures.

2. SIB Byte Structure

The SIB byte is 8 bits, divided as follows:

BitsNameDescription
7-6ScaleScale factor (00=1, 01=2, 10=4, 11=8)
5-3IndexIndex register (3 bits)
2-0BaseBase register (3 bits)
  • Scale (2 bits): Specifies the multiplier for the index register. Valid values are 1, 2, 4, or 8.

  • Index (3 bits): Specifies the index register. If set to 100 (binary), it means no index is used.

  • Base (3 bits): Specifies the base register for the addressing mode.

3. Scale Field Encoding

Scale BitsScale FactorUsage
001No scaling (index multiplied by 1)
012Index multiplied by 2
104Index multiplied by 4
118Index multiplied by 8

Scaling is typically used to access elements of arrays or structures, where the index represents an element offset, and scale corresponds to element size in bytes.

4. Index Field Encoding

The index field specifies which register is used as the index. The register codes correspond to:

Index BitsRegisterDescription
000RAXGeneral-purpose register
001RCXGeneral-purpose register
010RDXGeneral-purpose register
011RBXGeneral-purpose register
100NoneNo index (special encoding)
101RBPBase pointer (can be index)
110RSIGeneral-purpose register
111RDIGeneral-purpose register

When the index field is set to 100 (binary), it signifies that there is no index register used in the addressing, and only the base and displacement (if any) contribute to the address.

5. Base Field Encoding

The base field specifies the base register used in the memory addressing. The register codes correspond to:

Base BitsRegisterDescription
000RAXBase register
001RCXBase register
010RDXBase register
011RBXBase register
100RSPStack pointer register (special case)
101RBPBase pointer or displacement-only address (depends on Mod field)
110RSIBase register
111RDIBase register

 

Special cases occur depending on the Mod field of the ModR/M byte:

  • When Mod = 00 and Base = 101, this encodes a displacement-only addressing mode (no base register, a 32-bit displacement follows).

  • The RSP base code is never used directly without a SIB byte, as it conflicts with ModR/M encoding.

6. SIB Usage and Addressing Modes

The SIB byte enables multiple complex addressing scenarios:

  1. Base + Index × Scale + Displacement: The most common use, allowing calculation of an effective address with a base register, scaled index register, and optional displacement.

  2. Base + Index × Scale: When displacement is zero, the effective address is computed solely from base and scaled index.

  3. Index × Scale + Displacement (No Base): By setting Base field to 101 and Mod field to 00, displacement-only addressing combined with scaled index is possible.

  4. Base Only (No Index): When Index field is 100 (no index), SIB allows addressing with just a base register and optional displacement.

7. Example Encodings Using the SIB Byte

Example 1: Addressing [RAX + RDX*4 + 16]

  • Mod = 10 (32-bit displacement)

  • Reg = destination/source register (depending on instruction)

  • R/M = 100 to indicate SIB byte follows

  • SIB byte components:

    • Scale = 10 (4)

    • Index = 010 (RDX)

    • Base = 000 (RAX)

  • Displacement = 0x10 (32-bit)

Encoding:

  • ModR/M: 10 (Mod) + reg + 100 (R/M)

  • SIB: 10 (scale) + 010 (index) + 000 (base)

  • Displacement: 4 bytes (0x10)

Example 2: Addressing [RSP + RBP*1]

  • Mod = 00 (no displacement)

  • R/M = 100 (SIB byte follows)

  • SIB:

    • Scale = 00 (1)

    • Index = 101 (RBP)

    • Base = 100 (RSP)

This is a valid addressing mode where RSP is the base and RBP is used as an index scaled by 1.

8. REX Prefix Extension for SIB Fields

  • The REX prefix extends the SIB byte’s Index and Base fields by adding a high bit.

  • REX.X extends the Index field, allowing access to registers R8–R15 as index.

  • REX.B extends the Base field, allowing access to registers R8–R15 as base.

Example: To encode [R8 + R9*4] the REX prefix must set bits to extend these registers, as their lower 3-bit codes overlap with legacy registers.

9. Special Considerations

  • The SIB byte is mandatory for addressing modes involving RSP or any scaled indexing.

  • Use of SIB byte slightly increases instruction length but enables powerful addressing schemes.

  • Careful attention to the interaction between Mod, R/M, SIB, displacement, and REX prefixes is required to ensure correct encoding.

  • Not all instructions require or support SIB bytes; it is specific to memory operand addressing.

10. Summary

  • The SIB byte is an 8-bit extension to ModR/M that provides scale, index, and base for complex memory addressing.

  • It encodes a scale factor (1, 2, 4, or 8), an index register (or no index), and a base register (or displacement-only).

  • The SIB byte significantly expands the addressing modes available in x86-64 architecture.

  • Proper handling of the SIB byte and its interplay with ModR/M and REX prefixes is essential for correct machine code generation in an assembler.

Advertisements

Responsive Counter
General Counter
1272211
Daily Counter
765