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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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