Register Address Storage for MIPS

I allocated a certain amount of memory and would like to assign the location of this memory to a variable that I declared in the .data section of the program. I know how to assign a memory location for a variable, but as soon as I do this, how can I use this variable to access the allocated memory?

+3
source share
2 answers

If I understand your problem correctly, you will need to use the la(load address) instruction to get the address into the register. You will then use the lw(load word) and sw(store word) instructions to manage the data. For example, consider the following code snippet

.data
tmpval: .word 5

__start:
  sub $sp, $sp, 12
  sw  $ra, 0($sp) # Return addy
  sw  $t0, 4($sp)
  sw  $t1, 8($sp)

  la  $t0, tmpval
  lw  $t1, 0($t0)  # $t1 == tmpval == 5
  li  $t1, $2      # $t1 == 2
  sw  $t1, 0($t0)  # tmpval == 2

  lw  $ra, 0($sp)
  lw  $t0, 4($sp)
  lw  $t1, 8($sp)
  add $sp, $sp, 12
  jr $ra

, , $t0 ( ) .

+3

MIPS : load word (lw), load halfword (lh), (lb), (sw), (sh) (sb ) . , :

lw $t, C($s)

, $s C, $t. .. $t = [$ s + C]

:

sw $t, C($s)

$t $s C. .. [$ s + C] = $t

+3

All Articles