【发布时间】:2014-11-25 14:08:13
【问题描述】:
# 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
我一直在试图找出我的代码没有读取用户整数和存储的原因。我确信一切在语法上都是正确的。有人可以帮助我了解我是否使用错误的寄存器?
QTSimp 说 PC = 0x00400060 发生异常。
然后继续说存储中未对齐的地址= 0x1001005b。
它以 4 为增量进行(我假设是因为数组的索引方式。
最终错误消息是 异常 5 [存储中的地址错误] 发生并被忽略
Exception 4 [Address error in inst/data fetch] occurred and ignored(repeats 4 times)
【问题讨论】:
-
我在您的代码中没有看到任何在存储第一个数字后跳转回
input以读取另一个数字的内容。如果有你可能会有一个无限循环,因为你似乎没有增加$t0。 -
那些是我在程序中的东西,但回去编辑它我没有把它们放回去。我的问题是当我尝试输入第一个数字时出错。跨度>
-
每当您询问有关从工具/操作系统获得的错误的问题时,您需要在问题中包含确切的错误消息。
-
很抱歉。我在底部添加了错误。