|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
有谁帮我看看这个程序吗
我想输入一些数字 然后输入0就结束
然后把这些数字进行排序 然后输出
但是程序好像有问题 谁能帮我调试一下
.data
entry: .word 0, 0, 0, 0, 0, 0, 0, 0;
.main:
la $a0, entry
add $a1, $a0, $0
add $a2, $a0, $0 #save the adress of a0
add $s3, $ra, $0 #save $ra
entryloop:
addi $v0, 0, 5
syscall #input int
beq $v0, $0, entryexit #if input = 0 stop input
sw $v0, 0($a0) #save input to $a0
addi $a0, $a0, 4 #increase $a0
j entryloop
entryexit: lw $s0, 0($a1) #read first int in the array
beq $s0, 0, output #0 is the end of array
jal sort #call the sort function
addi $a1, $a1, 4 #increase a1
j entryexit
output: lw $a0, 0($a2) #read first int in the array
beq $a0, 0, exit #if it is 0 then exit
addi $v0, $0, 1
syscall
addi $a0, $0, ' '
addi $v0, $0, 11
syscall #output the int
addi $a2, $a2, 4 #increase a2, set the next int as the first int of the array
j output
exit: add $ra, $s3, $0 #restore ra
jr $ra
sort: #sort function
lw $t0, 0($a1) #read first input
compareloop: lw $t1, 0($a1) #compare loop
beq $t1, 0, exitsort #0 is the end of array
slt $t5, $t1, $t0 #compare the int with first int in the array
beq $t5, 0, pass #if the int have been read is bigger than first int, pass switch.
addi $t3, $t0, $0
addi $t0, $t1, $0
addi $t1, $t0, $0 #these three line switch t1, t0 if t1 is samller
pass: addi $a1, $a1, 4 #increase a1
j compareloop
exitsort: jr $ra |
|