You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RISC-V中sw指令操作数类型问题:使用标签而非寄存器报错

RISC-V汇编宏错误修复

你的代码报错是因为最后一行的寄存器使用错误,同时逻辑上不符合你的需求:

  • 你通过addi t0, t0, 1已经把更新后的位置存在t0里,但后续却错误地用了未赋值的t1来执行sw指令,这不仅逻辑错误,也会被汇编器判定为操作数异常。

修正后的完整宏代码:

.macro read_char
    li a7, 7 # read a character from the standard input
    ecall
    lw t0, char_pos # load the current position
    sb a0, (t0) # store the character at the current position
    addi t0, t0, 1 # increment the current position
    sw t0, char_pos # store the updated position

关键修改说明:

  • 将sw t1, char_pos替换为sw t0, char_pos,确保把递增后的位置(存储在t0中)正确写回char_pos内存地址。

内容的提问来源于stack exchange,提问作者justin8p

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 00:55:33