不用担心,您不必检查整个程序,而只需检查 caseThree 。我已经调试了程序(无论有什么知识),问题是当程序从 caseThree 返回并再次进入 while_mn 并尝试打印 option_prompt 我得到以下输出:Mars 4.5 output(我说的是奇怪的平方而不是数字),然后它停止工作。这项任务是明天的任务,老实说,我对所发生的事情感到困惑。你们是我的不得已的方法,因为我花了2个小时试图看问题出在哪里,但我没有任何进展。 (您不必浪费时间在程序的功能上,因为我确定这时$ v0会出问题)。老实说,非常感谢!
.data
.align 2
int_array_1: .space 20
int_array_2: .space 20
option_prompt: .asciiz "Give me an option between 1-5: "
valid_number: .asciiz "Give me a valid number please!!!!\n"
n_prompt: .asciiz "Give me the number N: "
space: .asciiz " "
newline: .asciiz "\n"
is_even_message: .asciiz "The number is even\n"
is_odd_message: .asciiz "The number is odd\n"
give_number_for_array: .asciiz "Give number for array: "
.text
main:
while_mn:
#print option prompt
li $v0, 4
la $a0, option_prompt
syscall
#get integer option
li $v0, 5
syscall
#store the option in $t0
move $t0, $v0
#jump to cases
beq $t0, 1, caseOne
beq $t0, 2, caseTwo
beq $t0, 3, caseThree
beq $t0, 4, caseFour
beq $t0, 5, caseFive
#print valid number message
li $v0, 4
la $a0, valid_number
syscall
j while_mn
exit_while_mn:
li $v0, 10
syscall
caseOne:
#print n prompt
li $v0, 4
la $a0, n_prompt
syscall
#get N number
li $v0, 5
syscall
#store the number N in $t1
move $t1, $v0
#set $t2=i to 1
addi $t2, $zero, 1
for_columns:
bgt $t2, $t1, exit_for_columns
#t3=k=1
addi $t3, $zero, 1
for_rows:
bgt $t3, $t2, exit_for_rows
#print k
li $v0, 1
la $a0, ($t3)
syscall
#print space
li $v0, 4
la $a0, space
syscall
#k+=1
addi $t3, $t3, 1
j for_rows
exit_for_rows:
#print newline
li $v0, 4
la $a0, newline
syscall
#i+=1
addi $t2, $t2, 1
j for_columns
exit_for_columns:
j while_mn
caseTwo:
#print n prompt
li $v0, 4
la $a0, n_prompt
syscall
#get N number
li $v0, 5
syscall
#store the number N in $t1
move $t1, $v0
#t2=0
addi $t2, $zero, 0
while_smaller:
bge $t2, $t1, exit_while_smaller
addi $t2, $t2, 2
j while_smaller
exit_while_smaller:
beq $t1, $t2, is_even
#print is_odd
li $v0, 4
la $a0, is_odd_message
syscall
j while_mn
is_even:
#print is_even
li $v0, 4
la $a0, is_even_message
syscall
j while_mn
caseThree:
addi $t1, $zero, 20
#the index
addi $t3, $zero, 0
while_fill_1:
beq $t3, $t1, exit_while_fill_1
#print give number
li $v0, 4
la $a0, give_number_for_array
syscall
#get number
li $v0, 5
syscall
move $s1, $v0
sw $s1, int_array_1($t3)
#index+=4
addi $t3, $t3, 4
j while_fill_1
exit_while_fill_1:
#the index
addi $t6, $zero, 0
while_fill_2:
beq $t6, $t1, exit_while_fill_2
lw $s5, int_array_1($t6)
addi $s5, $s5, 0
#t5 = t4*2^2=t4*4
sll $t5, $s5, 2
sw $t5, int_array_2($t3)
li $v0, 1
la $a0, ($t5)
syscall
#print space
li $v0, 4
la $a0, space
syscall
#index+=4
addi $t6, $t6, 4
j while_fill_2
exit_while_fill_2:
j while_mn
caseFour:
j while_mn
caseFive:
j exit_while_mn