Page 135 - A Practical Guide from Design Planning to Manufacturing
P. 135

108   Chapter Four

        for dynamically allocated variables. Displacement mode calculates the
        address as the sum of a constant and a register value. Some architec-
        tures allow the register value to be multiplied by a size factor. This
        mode is useful for accessing arrays. The constant value can contain the
        base address of the array while the registers hold the index. The size factor
        allows the array index to be multiplied by the data size of the array
        elements. An array of 32-bit integers will need to multiply the index
        by 4 to reach the proper address because each array element contains
        4 bytes.
          The indexed mode is the same as the displacement mode except the
        base address is held in a register rather than being a constant. The
        scaled address mode sums a constant and two registers to form an
        address. This could be used to access a two-dimensional array. Some
        architectures also support auto increment or decrement modes where
        the register being used as an index is automatically updated after the
        memory access. This supports serially accessing each element of an
        array. Finally, the memory indirect mode specifies a register that con-
        tains the address of a memory location that contains the desired address.
        This could be used to implement a memory pointer variable where the
        variable itself contains a memory address.
          In theory, an architecture could function supporting only register
        indirect mode. However, this would require computation instructions to
        form each address in a register before any memory location could be
        accessed. Supporting additional addressing modes can greatly reduce the
        total number of instructions required and can limit the number of reg-
        isters that are used in creating addresses. Allowing a constant or a con-
        stant added to a register to be used as an address is ideal for static
        variables allocated during compilation. Therefore, most architectures
        support at least the first three address modes listed in Table 4-12. RISC
        architectures typically support only these three modes.
          The more complicated modes further simplify coding but make some
        memory accesses much more complex than others. Memory indirect
        mode in particular requires two memory accesses for a single memory
        operand. The first access retrieves the address, and the second gets the
        data. VAX is one of the only architectures to support all the addressing
        modes shown in Table 4-12. The x86 architecture supports all these
        modes except for memory indirect. In addition to addressing modes,
        modern architectures also support an additional translation of memory
        addresses to be controlled by the operating system. This is called virtual
        memory.

        Virtual memory. Early architectures allowed each program to calculate
        its own memory addresses and to access memory directly using those
        addresses. Each program assumed that its instructions and data would
   130   131   132   133   134   135   136   137   138   139   140