【发布时间】:2017-03-14 11:47:24
【问题描述】:
对不起,我不是 MIPS 方面的专家。我需要导入一个介于 0 和 5 (0 4,我会收到一条错误消息 errorDimensionMessage,并且我的程序会重新启动函数 jal dimension,直到输入正确的值。在此之后,如果我输入正确的值(例如 3),程序将进入 jal exit 以退出。
(代码更新)
问题是在 5 (error) -> 3 (OK) 之后程序掉线了。
.data
InsertDimension: .asciiz " Insert an integer (n) with value between 0 and 5 (0 < n < 5): "
errorDimensionMessage: .asciiz " Error. Matrix dimension is not valid (e.g., 0 < n < 5)\n"
messageExit: .asciiz " Exit...\n"
.text
.globl main
main:
jal dimension
jal exit
exit:
la $a0, messageExit
li $v0, 4 # print string
syscall
li $v0, 10 # loads the service that exits
syscall
dimension:
move $s0, $ra # save return address into s0
la $a0, InsertDimension
li $v0, 4 # print string
syscall
li $v0, 5 # read an integer from console and put it in $v0!
syscall
jal isValidDimension
move $ra, $s0 #restore return address that was saved into s0
jr $ra #return
isValidDimension:
move $s1, $s0 # save return address into s0
beqz $v0, errorDimension
bgt $v0, 4, errorDimension
move $s0, $s1 # save return address into s0
jr $ra #return
errorDimension:
la $a0, errorDimensionMessage
li $v0, 4 # print string
syscall
j dimension # return to dimension
【问题讨论】:
标签: mips mars-simulator