
22
Chapter 2: Memory Model
AMD 64-Bit Technology
24593—Rev. 3.09—September 2003
2.2.5
RIP-Relative
Addressing
RIP-relative addressing—that is, addressing relative to the 64-
bit instruction pointer (also called program counter)—is
available in 64-bit mode. The effective address is formed by
adding the displacement to the 64-bit RIP of the next
instruction.
In the legacy x86 architecture, addressing relative to the
instruction pointer (IP or EIP) is available only in control-
transfer instructions. In the 64-bit mode, any instruction that
uses ModRM addressing (see “ModRM and SIB Bytes” in
Volume 3) can use RIP-relative addressing. The feature is
particularly useful for addressing data in position-independent
code and for code that addresses global data.
Programs usually have many references to data, especially
global data, that are not register-based. To load such a program,
the loader typically selects a location for the program in
memory and then adjusts the program’s references to global
data based on the load location. RIP-relative addressing of data
makes this adjustment unnecessary.
Range of RIP-Relative Addressing.
Without RIP-relative addressing,
instructions encoded with a ModRM byte address memory
relative to zero. With RIP-relative addressing, instructions with
a ModRM byte can address memory relative to the 64-bit RIP
using a signed 32-bit displacement. This provides an offset
range of
±
2GB from the RIP.
Effect of Address-Size Prefix on RIP-relative Addressing.
RIP-relative
addressing is enabled by 64-bit mode, not by a 64-bit address-
size. Conversely, use of the address-size prefix does not disable
RIP-relative addressing. The effect of the address-size prefix is
to truncate and zero-extend the computed effective address to
32 bits, like any other addressing mode.
Encoding.
For details on instruction encoding of RIP-relative
addressing, see in “RIP-Relative Addressing” in Volume 3.
2.3
Pointers
Pointers are variables that contain addresses rather than data.
They are used by instructions to reference memory. Instructions
access data using near and far pointers. Stack pointers locate
the current stack.