Search code examples
assemblyx86-64addressing-mode

What is the allowed range for offsets in for example LEA RAX, [RBX+off]


Now I am pretty sure this is a basic question but I couldn't find the answer. How many bits at most can offset be ?


Solution

  • There are six addressing modes supporting this format. The assembler will automatically pick the shortest addressing mode into which the displacement fits. The three relevant of these addressing modes are:

    • register indirect, no displacement (displacement must be zero)
    • register indirect, 8 bit displacement (displacement must be between −128 and 127)
    • register indirect, 32 bit displacement (displacement must be between −2147483648 and 2147483647)

    It is not possible to encode a greater displacement than what these addressing modes support. If you need a greater displacement, perform arithmetic to load it. For example, do

    mov rax, 123456789abcdef0h
    lea rax, [rbx+rax]