MIPS Memory Addressing Modes (Cont.)


Base Addressing Mode
Address of operand is the contents of register plus offset from instruction.

Relative Addressing Mode Register Indirect
       .data
 val:  .word  0x00100100
 # 0xnn: hexadecimal nn

       .text 
       lh  $a0, val+2
       li  $v0, 1
       syscall
       .data
       .byte  1
 val:  .byte  2
       .byte  3

       .text 
       lb  $a0, val-1
       li  $v0, 1
       syscall
     .data
 s:  .asciiz  "abc" 

     .text 
     la  $t0, s+2 
     la  $a0, ($t0)
     li  $v0, 4
     syscall
Output Output Output









Register Indirect Base Addressing Mode
     .data
 s:  .asciiz  "abc" 

     .text 
     la    $t0, s
     addi  $t0, $t0, 1
 # addi: add immediate
     lb    $a0, ($t0)
     li    $v0, 11
     syscall
     .data 
 s:  .asciiz  "abc"

     .text 
     li  $t0, 2
     la  $a0, s($t0) 
     li  $v0, 4
     syscall
       .data
 val:  .byte  0x01
       .half  0x0302
       .word  0x07060504

       .text 
       la  $t0, val+1
       lb  $a0, 2($t0) 
       li  $v0, 1
       syscall
Output Output Output













      “Wisely and slow; they stumble that run fast.”    
      ― William Shakespeare, Romeo and Juliet