如何在RISC-V汇编中使用数组

问题描述 投票:0回答:1

我正在学习RISC-V组装,我需要使用数组来解决我要解决的问题;问题是我正在使用的模拟器(RARS)给了我一个错误:Error in /home/username/file_name line 8: Runtime exception at 0x00400010: address out of range 0x000003e8.

这是我到目前为止编写的代码:

.data
arr: .word 1000
e0: .word 5

.text
lw t1, arr # load arr into t1
lw t2, e0 # Load e0 value into t2
sw t2, 0(t1) # save t2 value into arr[0]

我做错了什么?

assembly riscv
1个回答
0
投票

sw t2, 0(t1)指令将寄存器t2的内容存储到寄存器t1提供的存储地址中。但是,t1不包含对应于标签arr的地址-值1000的存储地址-因为t1是由指令lw t1, arr初始化的,因此加载content将与arr对应的地址的装入t1,即,将值1000装入t1

相反,将lw t1, arr替换为la t1, arr,这确实会将t1表示的地址加载到arr中。

© www.soinside.com 2019 - 2024. All rights reserved.