简体   繁体   English

如何在 RISC-V 程序集中使用数组

[英]How to use an array in RISC-V Assembly

I'm learning RISC-V assembly and i need to use array for an exercise that i'm solving;我正在学习 RISC-V 汇编,我需要将数组用于我正在解决的练习; the problem is that the simulator that i'm using( RARS ) gave me an error:问题是我正在使用的模拟器( RARS )给了我一个错误:
Error in /home/username/file_name line 8: Runtime exception at 0x00400010: address out of range 0x000003e8.

This is the code i wrote so far:这是我到目前为止编写的代码:

.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]

What i'm doing wrong?我在做什么错?

The instruction sw t2, 0(t1) stores the content of the register t2 into the memory address provided by the register t1 .指令sw t2, 0(t1)将寄存器t2的内容存入寄存器t1提供的内存地址中。 However, t1 does not contain the address that corresponds to the label arr – the address where the value 1000 is stored – because t1 was initialized by the instruction lw t1, arr , and this loads the content of the address corresponding to arr into t1 , ie, it loads the value 1000 into t1 .但是, t1不包含与标签arr对应的地址——存储值1000的地址——因为t1是由指令lw t1, arr初始化的,这会将与arr对应的地址的内容加载到t1 ,即,它将值1000加载到t1

Instead, replace lw t1, arr by la t1, arr , which does load into t1 the address that arr is representing.相反,将lw t1, arr替换为la t1, arr ,这arr表示的地址加载到t1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM