MIPS编程地址存储和加载 [英] MIPS Programming Address Storing and Loading
问题描述
我无法理解如何在MIPS中加载和存储特定地址.我需要获取一个项目的地址,并将其存储在另一个项目的单词中.如何将项目的地址作为单词加载,以便可以将其存储为单词?我将如何加载该单词并将其转换为地址?这可能吗?我需要能够像双向链接列表一样链接项目,其中每个项目都指向下一个.
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.
推荐答案
当然,使用la
获取标签的地址,并使用lw
/sw
从该地址加载/存储该地址或将其存储到某个地方.
Sure, use la
to get the address of a label, and lw
/sw
to load/store that address from/to somewhere.
一个例子:
.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
这篇关于MIPS编程地址存储和加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!