问题描述
我的排序代码有问题。所以 printFirstArray 和第二个循环函数打印出来 排序之前的初始列表,但是当我执行 printArray 和 finalLoop 时,它不输出任何内容
我假设那是因为前面的函数将地址设置在堆栈的底部,所以没有输出。如果是这种情况,我该如何重置它以使其指向顶部
.data
vals: .space 4000
message1: .asciiz "Enter an integer: 9999 to sort \n"
message2: .asciiz "Sorted array: \n"
message3: .asciiz "You have entered: \n"
next_line: .asciiz "\n"
.text
.globl main
main:
la $a1,vals # base address of the array
li $a2,9 # $a2 = 9;
li $t0,0 # i = 0;
li $t1,9999
loop:
#sends out first msg
la $a0,message1
li $v0,4
syscall
li $v0,5
syscall
beq $v0,$t1,printFirstArray #begins sorting if 9999 is inputted
addi $t0,$t0,4
sw $v0,($a1)
addi $a1,$a1,4 # moves array over by 1
j loop
printFirstArray:
la $a1,vals
la $a0,message3
li $v0,4
syscall
secondLoop:
#prints sequence
blez $t0,sort
li $v0,1
lw $a0,0($a1)
syscall
la $a0,next_line
li $v0,4
syscall
addi $a1,4
addi $t0,-4
j secondLoop
sort:
la $t4,vals #t0 is number up to outter loop
la $t1,vals #t1 is number comparing to inner loop
addi $t1,4
la $t8,vals
add $t8,$t8
la $t9,vals
add $t9,$t9
addi $t9,$t9,-4
loopsec:
lw $t2,($t4) #gets number 1 of outter loop
lw $t3,($t1) #gets number 2 of inner loop
blt $t2,$t3,next #executes if a swap isnt necessarry
sw $t3,($t4) #swap
sw $t2,($t1)
next:
addi $t1,4
blt $t1,$t8,loopsec #checks if inner loop is done
addi $t4,$t4,4 #if yes then increments the outer loop
move $t1,$t4
addi $t1,4
blt $t4,loopsec #jumps to loops if outer loop is done
printArray:
la $a1,vals
la $a0,message2
li $v0,4
syscall
finalLoop:
#checks each line until t0 is less than or equal to 0
blez $t0,done
li $v0,-4
j finalLoop
done:
j done
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)