DHA Suffa University Department of Computer Science Computer Organization & Assembly Language FALL 2021 Lab # 05 (Direct and Indirect Addressing)
DHA Suffa University Department of Computer Science Computer Organization & Assembly Language FALL 2021 Lab # 05 (Direct and Indirect Addressing)
Register Addressing:
The simplest addressing mode is the register addressing. Instructions using registers
execute fast because they do not have the delay associated with memory access.
However, the number of registers is limited.
Register addressing is a form of direct addressing. The value in the register is an operand
instead of being a memory address to an operand.
For example: add $t0, $t1, $t2
Immediate Addressing:
One operand is a constant within the instruction itself. The advantage of using it is that
there is no need to have extra memory access to fetch the operand. But keep in mind that
the operand is limited to 16 bits in size.
For example: addi $t0, $t0, 5 or j target
Base Addressing:
sw $t2, -12($t0)
stacks; easy to access elements at offset from stack pointer or frame pointer
Indirect addressing:
lw $t2, ($t0)
load word at RAM address contained in $t0 into $t2
sw $t2, ($t0)
store word in register $t2 into RAM at address contained in $t0
Example of indirect addressing:
.data
num: .word 12,14,16,18,20
.text
li $t1, 0
li $t2, 5
la $t0, num # load base address of array into register $t0
Loop:
beq $t1, $t2, exit
lw $t3,($t0) # a=*b
li $v0, 1
move $a0, $t3
syscall
b Loop
exit:
li $v0, 10
syscall
.text
li $t1, 13 # $t1 = 13
sw $t1, 4($t0) # second array element set to 13
li $t1, -7 # $t1 = -7
sw $t1, 8($t0)
la $t4, array1
lw $t1, 0($t4)
li $v0, 1
move $a0, $t1
syscall
lw $t1, 4($t4)
li $v0, 1
move $a0, $t1
syscall
lw $t1, 8($t4)
li $v0, 1
move $a0, $t1
syscall
li $v0, 10
syscall
LAB TASKS