MIPS:地址超出范围

时间:2014-09-26 00:20:42

标签: arrays mips memory-address

我试图创建一个给用户输入的字符串(输入)的程序,看它是否匹配names数组中的任何字符串。当我试图将names数组中的每个名称与输入的字符串(输入)进行比较时,我不断收到以下消息:

  

第37行:0x00400064处的运行时异常:地址超出范围0x1040100c

我不确定我对数组中项目的寻址是否关闭或者这些数组项中特定字符的地址是否已关闭。在过去的几个小时里,我一直在撞墙,试图找出我的地址关闭的原因。我已经查看了Stack Exchange上的其他答案,但是从数组中获取一个字符串,然后通过该字符串并将其与另一个字符串进行比较,还有其他任何问题

.data
input: .space 64
names: .asciiz "steve","john","chelsea","julia","ryan"
ages: .byte 20,25,22,21,23
greeting: .asciiz "Please enter a name: \n"
notfoundmessage: .asciiz "Not found!"
foundmessage: .asciiz "good for you! found"

.text
li $v0,4
la $a0, greeting
syscall #asks for name
li $v0,8
la $a0,input #input address stored at $a0
li $a1,64
syscall
li $t0,0 #current element in array
la $a1,names #stores names array address

loop:
add $a1,$a1,$t0 #adds offset
jal checkName
bne $v0,$zero,found #if one is returned, word has been found
beq $t0,5,notFound #if counter reaches 5, whole array has been searched
addi $t0,$t0,4 #add multiples of 4 to each base address to get next array element
j loop

checkName:
move $t3, $a0 
move $t4, $a1
li $t5, 0 #offset 

loop2:
add $t3, $t3, $t5
add $t4, $t4, $t5
lb $t6, 0($t3)
lb $t7, 0($t4) **#THIS LINE IS THE PROBLEMATIC ONE**
bne $t6, $t7, mismatch
beq $t6, $zero, doubleCheck
beq $t7, $zero, doubleCheck
addi $t5,$t5,1
j loop2

doubleCheck:
bne $t6,$t7,mismatch
li $v0,1
jr $ra

mismatch:
li $t5,0
li $v0,0
jr $ra

notFound:
li $v0,4
la $a0,notfoundmessage
syscall
li $v0,10
syscall

found:
li $v0,4
la $a0,foundmessage
syscall
li $v0,10
syscall

0 个答案:

没有答案