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
相关产品推荐
相关产品推荐

