Chapter 05-Part II
Chapter 05-Part II
Section 5.0
Addressing
Addressing Issues
– Register
– PC-relative
– Indirect
Addressing Modes (II)
• Immediate
– The operand contains the value of the datum.
– Eg: add $r4, $r2, #5
$r4 = Data in register $r2 + 3
• Direct (pseudo-direct for MIPS)
– The operand contains the memory address of the datum.
– Eg: add $r4, $r2, (1024)
$r4 = Data in register $r2 + Data at memory address 1024
• Register
– The operand contains the register designation where the
datum is located.
– Eg: add $r4, $r2, r3
$r4 = Data in register $r2 + Data in register $r3
Addressing Modes (III)
• PC-relative
– The operand contains the offset from the PC
– Eg: beg $r1, $r2, 25
If ($r1 = $r2) go to PC = PC + offset (25)
PC – Program Counter
• base / Indexed
– A register contains a base address and an operand holds
a displacement from this base
Note: the base register may be another operand or implicit
– Eg: lw $r1, 100($r2)
r1 = Memory(r2 + 100)
Addressing Modes (IV)
• Indirect
– The operand contains the (memory) address of the datum
– E.g: LD $r3, ($r2)
$r3 = Contents of memory address in register $r2
0x1000
35 0x1004
0x1008
$r2 0x1004 0x100c
memory
Addressing Modes – Example
• Immediate - 800
• Direct – 900 (800 contains the intended value)
• Base - 500 (800 is added to the content of the base register = 300, which gives
1100, and the content of word 1100 is retrieved)
• Indirect– 1000 (800 has the memory address 900, and memory address 900
contains the value)
base register
900 800 300
…
1000 900
…
700 1000
…
500 1100