Mips函数参数和返回值
我正在尝试使用mips assembly创建一个哈希表。由于某些原因,我的Mips函数参数和返回值,mips,Mips,我正在尝试使用mips assembly创建一个哈希表。由于某些原因,我的InsertKey功能无法正常工作。当我尝试使用控制台时,它只是冻结,没有错误消息 InsertK: li $v0, 4 la $a0, enterIntPrompt syscall li $v0, 5 syscall move $a0, $v0 # key in a0 li $t0, 0 la $a1, Hash # table address i
InsertKey
功能无法正常工作。当我尝试使用控制台时,它只是冻结,没有错误消息
InsertK:
li $v0, 4
la $a0, enterIntPrompt
syscall
li $v0, 5
syscall
move $a0, $v0 # key in a0
li $t0, 0
la $a1, Hash # table address in a1
bgt $a0, $t0, JInsertKey
li $v0, 4
la $a0, notInsertKeyMes
syscall
j whileloop
JInsertKey:
jal InsertKey
j whileloop
我怀疑我把传递的值搞砸了,但我什么也找不到。教科书说,使用$v0
-$v2
寄存器作为函数调用的返回值,使用$a0
-$a3
作为函数参数是一种很好的做法。
这是调用InsertKey
函数的代码:
InsertKey:
jal FindKey
move $t0, $v0 # position in t0
li $t1, -1
bne $t0, $t1, prints
bgt $s1, $s0, dostuff
li $v0, 4
la $a0, hashTableFullMes
syscall
jr $ra
dostuff:
jal HashFunction
move $t0, $v0
li $t3, 4
multu $t0, $t3
mflo $t3
la $a1, Hash
add $a1, $a1, $t3 # a1 adress hash[position]
sw $a0, ($a1)
addi $s0,1
jr $ra
prints:
li $v0, 4
la $a0, keyAlreadyInTableMes
syscall
jr $ra
FindKey
和HashFunction
工作正常。有人能找出这个代码的问题吗?我真的没有主意了
编辑:Findkey
返回找到的键的位置,否则-1
InsertKey:
jal FindKey
上述操作会导致InsertKey
的$ra
被InsertKey
+8的地址覆盖,因此当InsertKey
返回时,它会返回自身,而不是其调用者
在调用任何其他函数之前,您需要保存
InsertKey的返回地址和参数。在调试器中逐步检查您的代码将帮助您理解它不起作用的原因:我确实这样做了,我正在使用QTSpim,当我尝试插入一个数字时,它会崩溃