MIPS Programming Address Storing and Loading

2019-08-01 18:32发布

I'm having trouble understanding how to load and store specific addresses within MIPS. I need to take the address of an item and store it within a word in another item. How do I load the address of the item as a word so it can be stored as a word? And how would I go about loading the word and turning it into an address? Is this possible? I need to be able to link items like a doubly linked list where each item points to the next.

标签: mips
1条回答
太酷不给撩
2楼-- · 2019-08-01 19:03

Sure, use la to get the address of a label, and lw/sw to load/store that address from/to somewhere.

An example:

.data
list: .space 8*4

item1: .word 123

.text
.globl main
main:

la $a1,list     # a1 = address of list

la $t0,item1    # t0 = address of item1
sw $t0,($a1)    # store item1's address in the first word of list

# ...

lw $t0,($a1)    # t0 = address of item1
lw $a0,($t0)    # a0 = item1
li $v0,1        # syscall 1 (print_int)
syscall

li $v0, 10      # syscall 10 (exit)
syscall
查看更多
登录 后发表回答