首页 > 解决方案 > 如何在 RISC-V 中的 read_string 之后 print_string

问题描述

我正在尝试读取字符串,将其保存到注册表而不是输出。当我尝试执行以下操作时,出现错误“源字符串必须从双字边界开始:

s1:    DC "Input a string"
       addi x30, x0, s1
       ecall x0, x30, 4 ;info string
       ecall x6, x0, 8 ;read_string
       ecall x0, x6, 4 ;info string //this is where there error is

我很难找到有关如何使用 RISC-V v0.46 执行此操作的任何文档

标签: riscv

解决方案


发现我需要将数据加载到内存中才能读取它,解决方法如下

s1:    DC "Input a string"
       addi x30, x0, s1
       ecall x0, x30, 4 ;info string
       ecall x6, x0, 8 ;read_string
       //load into memory
       sd x6, dst(x0)
       addi x29, x0, dst
       ecall x0, x29, 4 ;info string
dst:   DM 1

推荐阅读