如何将单词存储到用户先前在 MIPS 中输入的地址中?

问题描述

我刚刚开始学习 MIPS,但我一直坚持使用此代码

程序概述:首先用户输入一个数字,该数字应该是最终结果的存储地址,然后输入数组信息,计算奇数的乘积,程序将乘积存储在地址用户输入和寄存器 $s3

问题概述: 问题在于将产品存储到用户输入的内存地址中,您可以在主程序末尾附近找到#error注释的代码行。我收到错误消息:“地址遥不可及”。什么可能导致这个问题?我尝试了很多东西,但我无法弄清楚。

示例测试用例:
124000 # 需要存放最终结果的内存位置
10 # 数组长度
1 3 5 7 8 9 4 6 10 4 # 数组编号

输出:945

这是我的代码

.data

    numbers: .space 80
    

.text

    main:
        li $v0,5
        syscall

        move $s0,$v0 # $s0 = the address where I need to store the product

        li $v0,5
        syscall
        move $s1,$v0 # $s1 = size of numbers array

        move $t0,$zero # $t0 = counter for the loop
        la $t1,numbers # $t1 = address of numbers

        numbersInputLoop:
            beq $t0,$s1,endOfInput
            addi $t0,$t0,1

            li $v0,5
            syscall
            move $t2,$v0
            sw $t2,0($t1)

            addi $t1,$t1,4

            j numbersInputLoop

        endOfInput:

        jal calculateProduct
        
        # storing in memory and in register s3
        sw $v1,0($s0) # error
        move $s3,$v1
        
        move $a0,$v1
        li $v0,1
        syscall

        li $v0,10
        syscall

# end of main and beginning of procedure
    calculateProduct:
        addi $sp,$sp,-8
        sw $s0,0($sp)
        sw $s1,4($sp)  
    
        li $t2,1 # product

        move $t0,$zero # counter
        la $t1,numbers
        loop:
            beq $t0,endOfLoop
            addi $t0,1

            lw $t3,0($t1)
            li $t4,2
            div $t3,$t4
            mfhi $t5
            
            beq $t5,$zero,else
            
            mult $t2,$t3
            mflo $t2
            else:

            addi $t1,4

            j loop

        endOfLoop:

        
        lw $s1,4($sp)
        lw $s0,0($sp)  
        addi $sp,8

        move $v1,$t2
        jr $ra

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)