assemblyx86cpu-registerscpu-architectureaddressing

What is the minimum number of addressing modes necessary for computation?


In x86 Assembler, given that you have

why do you need Indexed and Base Pointer addressing modes? Each could be replaced by a loop as far as I know.

Also Indirect mode doesn't seem to be overly useful either, since you can simply use Direct mode instead to reference the memory address. What is the purpose of first accessing a register which then contains a pointer to a memory address?

In short, which addressing modes are really necessary?


Solution

  • Although in theory 'addressing mode' can be used to refer to the operand type, it's a bit confusing since it doesn't involve an address. The Intel manual uses 'addressing mode' to refer to memory addressing, and I will use this definition.

    In assembly, an operand can be :

    In the x86 architecture, the "addressing mode" is only for the last type of operands : memory operands (addresses), and refers to the methods available to calculate the addresses. The addressing modes can be summarized in a single configurable addressing mode :

    address = REG_base + REG_index*n + offset
    

    REG_base, REG_index, n and offset are all configurable, and can all be omitted (but you need at least one, obviously).

    address = offset is called immediate, direct or absolute addressing.
    address = REG_base is called register indirect addressing.
    address = REG_base + REG_index is called base plus index addressing.
    Similarly, you can add an offset (offset) and a scale (n).

    Strictly speaking, you only need one mode to do everything : register indirect addressing (address = REG). With that, if you need to access memory, you can calculate any address you want in a register, and use it to do the access. It can also replace direct register operands by using memory instead, and immediate operands by constructing values with arithmetic. However, for a practical instruction set, you would still immediate operands to load addresses effectively, and register operands are needed if you don't want pointer-only registers.

    All the other addressing modes beside register indirect are here for convenience, and they are indeed really convenient :

    These addressing modes don't need much calculations from the CPU : only additions and shifts. Considering x86 can do a multiplication every cycle, those operations are trivial but still very convenient.