Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Recursion &引用;(错误)试图写入无效的内存地址“;尝试存储堆栈指针时_Recursion_Assembly_Stack_Riscv - Fatal编程技术网

Recursion &引用;(错误)试图写入无效的内存地址“;尝试存储堆栈指针时

Recursion &引用;(错误)试图写入无效的内存地址“;尝试存储堆栈指针时,recursion,assembly,stack,riscv,Recursion,Assembly,Stack,Riscv,我试图在Jupiter环境(risc32)下学习RISC-V,我遇到了一个问题,要求我用RISC-V编写递归程序。我似乎无法让sw指令工作,因为它总是给出一个错误:无效地址 我尝试了不同的偏移量、不同的寄存器等,但似乎没有任何效果 .globl __start .rodata msg_input: .string "Enter a number: " msg_result: .string "The result is: " newline: .string "\n" .text

我试图在Jupiter环境(risc32)下学习RISC-V,我遇到了一个问题,要求我用RISC-V编写递归程序。我似乎无法让sw指令工作,因为它总是给出一个错误:无效地址

我尝试了不同的偏移量、不同的寄存器等,但似乎没有任何效果

.globl __start

.rodata
  msg_input: .string "Enter a number: "
  msg_result: .string "The result is: "
  newline: .string "\n"

.text

__start:
  # prints msg_input
  li a0, 4
  la a1, msg_input
  ecall
  #read from standard input
  li a0, 5
  ecall
  #initialize stack
  addi x31, x0, 2
  addi sp, x0, 800
  mv x5, a0
  jal x1, recfunc
  mv t0, x5

recfunc:
  addi sp, sp, -8
  sw x1, 0(sp)
  bge x5, x31, true
  lw x1, 0(sp)
  addi x10, x0, 1
  addi sp,sp, 8
  jalr x0, 0(x1)


true:  
  div x5, x5, x31
  jal x1, recfunc
  lw x1, 0(sp)
  addi sp,sp,8
  mul x10, x10, x31
  addi x10, x10, 1
  jalr x0, 0(x1)

result:
  #prints msg_result
  li a0, 4
  la a1 msg_result
  ecall
  #prints the result in t0
  li a0, 1
  mv a1, t0
  ecall
  #ends the program with status code 0
  li x5, 10
  ecall
错误发生在:

 sw x1, 0 (x2)

(错误)试图写入无效内存地址0x00000318,请显示。如果这是您的全部代码,那么它将分为
func
。。。你想在那之前退出或返回。对不起,第一次在这里提问。引导模式指示我只为启动器添加相关部分,执行永远不会得到
结果
。将该块移动到
recfunc
@Jester之前,也许我可以得到结果?确实没有理由,但这也会起作用。简单的解决方案是移动代码本身。