在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!)    创芯人才网--重磅上线啦!
查看: 2180|回复: 1

简单排序 代码求助

[复制链接]
发表于 2008-3-26 09:10:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

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
发表于 2009-5-31 18:01:27 | 显示全部楼层
谢谢共享!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

关闭

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-3-29 20:12 , Processed in 0.040789 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表