



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Addressing modes
1. Immediate Addressing Mode Definition : The operand is directly specified as a constant within the instruction itself. Use : For loading or operating on constant values. Format : assembly opcode destination, constant Example : assembly addi $t0, $0, 5 # Load the constant value 5 into register $t Explanation : Here, the immediate value 5 is used directly as an operand. 2. Register Addressing Mode Definition : The operand is located in a CPU register. Use : Fast access to data stored in registers. Format : assembly opcode destination, source1, source Example : assembly add $t0, $t1, $t2 # $t0 = $t1 + $t Explanation : Operands $t1 and $t2 are located in CPU registers. The result is stored in $t0. 3. Direct Addressing Mode (Absolute Addressing)
Definition : The memory address of the operand is explicitly specified in the instruction. Use : Access a specific memory location. Format : assembly opcode destination, memory_address Example : assembly lw $t0, 0x1000 # Load the value at memory address 0x1000 into register $t Explanation : The instruction directly specifies the memory address (0x1000).
4. Indirect Addressing Mode Definition : The instruction specifies a register or memory location containing the address of the operand. Use : Access memory indirectly via a pointer. Format : assembly opcode destination, (register) Example : assembly lw $t0, ($t1) # Load the value from the memory address stored in $t1 into $t Explanation : The address of the operand is stored in $t1. The value at that address is loaded into $t0. 5. Indexed Addressing Mode
Format : assembly opcode destination, (register) Example : assembly CopyEdit lw $t0, ($t1) # Load the value from the memory address stored in $t1 into $t Explanation : The effective address is stored in $t1, and the operand is fetched from that address.
8. Displacement Addressing Mode Definition : Combines a base address from a register, an index from another register, and an optional offset. Use : Complex addressing for arrays, structures, or object-oriented programming. Format : assembly opcode destination, offset(base_register, index_register) Example : assembly lw $t0, 4($t1, $t2) # $t0 = memory[$t1 + $t2 + 4] Explanation : The effective address is calculated as value_in_$t1 + value_in_$t2 + 4. The value at this address is loaded into $t0. Comparison Table Addressing Mode Example Description Immediate addi^ $t0,^ $0, 5^ Operand is a constant value in the
Addressing Mode Example Description instruction. Register add $t0, $t1, $t Operand is in a register. Direct lw^ $t0,^ 0x^ Operand is in a specific memory address. Indirect lw^ $t0,^ ($t1)^ Address of operand is stored in a register. Indexed lw^ $t0,^ 4($t1)^ Address = base_register + offset. Stack push $t0, pop $t Operand is on the stack. Register Indirect lw $t0, ($t1) (^) Register contains the operand address. Displacement lw $t0, 4($t1, $t2) Address = base_register + index_register + offset.