Arrays MIPS-读取整数错误

Arrays MIPS-读取整数错误,arrays,input,integer,mips,Arrays,Input,Integer,Mips,我一直在试图找出我的代码没有读取用户整数和存储的原因。我确信所有的语法都是正确的。有人能帮我理解我是否用错了寄存器吗 QTSpim表示异常发生在PC=0x00400060 然后继续说存储区中未对齐的地址=0x1001005b 它以4的增量进行(我假设是因为数组的索引方式) 最后的错误消息是 发生并忽略了异常5[存储区中的地址错误] # Programming Project 2 # Noah Heath # @02685972 .data # Data declaration #

我一直在试图找出我的代码没有读取用户整数和存储的原因。我确信所有的语法都是正确的。有人能帮我理解我是否用错了寄存器吗

QTSpim表示异常发生在PC=0x00400060

然后继续说存储区中未对齐的地址=0x1001005b

它以4的增量进行(我假设是因为数组的索引方式)

最后的错误消息是 发生并忽略了异常5[存储区中的地址错误]

# Programming Project 2
# Noah Heath
# @02685972

.data # Data declaration
      # A+B -(C-D x E)

string1: .asciiz "Please enter an integer from range 0 to 32768: "
string2: .asciiz "Next integer: "
string3: .asciiz "Invalid input. Start over. "
userinput: .space 100
var6: .asciiz "The result of A+B -(C-D x E) is: "
.text

main:
    la $a0, string1 #load string one and print
    li $v0, 4
    syscall

    la $a1, userinput 
    li $t1, 5 #set temporary variable to 5
    li $t0, 0 #start of counter

input:  
    beq $t0, $t1, exit
    li $v0, 5 # read integer
    syscall
    blt $v0, $zero, input # if input is less than zero
    bgt $v0, 32768, input # if input is greater than 32768
    sw $v0, 0($a1)
    addiu $a1, $a1, 4

exit:
    la $t3, userinput # stores base address of user input array into $t3
    lw $t4, ($t3) # load first number
    lw $t5, 4($t3) # load second number
    lw $t6, 8($t3) # load third number
    lw $t7, 12($t3) # load fourth number
    lw $t8, 16($t3) # load fifth number
    add $s1, $t4, $t5 # adds 1 and 2 into $t0
    mult $t7, $t8 # multiplies 2 and 3
    mflo $s2 # retrieves from register
    sub $s3, $t6, $s2 # subtracts 7 from 6
    sub $s4, $s1, $s3 # subtracts 1 from 3
    move $a0, $s4 # moves result into a0

    li $v0, 1 # instruction to print result
    syscall # call operating system to perform operation

    li $v0, 10 # exit instruction
    syscall

请求用户输入的代码没有问题

我猜您的问题是,您试图将用户输入的内容存储在一个不对齐的地址(发出
sw$v0,0($a1)
)中

您应该在
用户输入
标签前添加指令
.align 2
,例如:

Exception 4 [Address error in inst/data fetch] occurred and ignored(repeats 4 times)

我看不到你的代码中有任何东西在第一个数字存储后跳回
输入
读取另一个数字。如果有,你可能会有一个无限循环,因为你似乎没有增加
$t0
。这些都是我在程序中拥有的东西,但我返回并编辑它,我没有把它们放回。我的问题是m表示我在尝试输入第一个数字时出错。无论何时,当你询问有关工具/操作系统错误的问题时,你都需要在问题中包含准确的错误消息。对此表示抱歉。我已在底部添加了错误。谢谢!我还是MIPS新手,由于时间限制,我们的说明现在有点仓促ints。你能解释一下为什么会解决我的问题吗?@Noaheath:它解决了你的问题,因为MIPS中的字内存访问必须是字对齐的。汇编指令
.align 2
确保你示例中的下一个数据(
userinput
)在字边界对齐。啊,这现在真的很有意义。谢谢。
string3: .asciiz "Invalid input. Start over. "
.align 2
userinput: .space 100