Why we have addressing modes
The addresing modes are used because sometimes is more efficient to not to store the operands in the instruction format. Operands can be located at:
- Directly in the instruction (Inmmediates)
- In a register
- In memory
Addressing modes
Inmediate addressing (5Bits)
The 3rd parameter value is an inmediate.
Example:
add $1, $2, 99 → We use 99 as the 3rd parameterDirect addressing (5Bits)
The 3rd parameter value is contained in a register
Example:
add $1, $2, $3 → We use the value stored at $3 as the 3rd parameterIndirect addressing with offset (5Bits)
The 3rd parameter value is the result of adding the value of the register and an offset value:
offset + $register Example:
lw $1, 99($3) → We use the value at $3 + 99 as the 3rd parameterRelative addressing (labels)
The 3rd parameter value is the result of adding the value of the register and an offset value:
offset + $PCExample:
bne $1, $2, MyLabel → We use a label to access an address in memoryPseudoindirect addressing
The 3rd parameter value is the result of adding the value of the register and an offset value
Example:
j 9999 → We use the value 9999 to be shifted by 2 (x4)