在 MIPS 中对用户输入的数字列表进行排序
我正在编写 MIPS 程序,该程序将检查从终端输入的 10 个数字的列表。 这些数字将按升序输出在终端上。 下面是我的 MIPS 程序...请有人帮我研究一下,因为我正在运行并且无法正常工作...
.data
array: .space 40
prompt: .asciiz "Enter a number: "
spacee: .asciiz " "
output: .asciiz "The numbers are: "
.text
main:
li $t1,10
la $a1,array
loop:
addi $t1,$t1,-1
li $v0,4
la $a0,prompt
syscall
li $v0,5
syscall
sw $v0,0($a1)
addi $a1,$a1,4
bnez $t1,loop
li $t1,9
li $t2,9
la $a1,array
loop1:
beqz $t2,here
addi $t2,$t2,-1
lw $t5,0($a1)
lw $t6,4($a1)
add $a1,$a1,4
ble $t5,$t6,loop1
sw $t5,0($a1)
sw $t6,-4($a1)
bnez $t2,loop1
here:
la $a1,array
addi $t1,$t1,-1
add $t2,$t2,$t1
bnez $t1,loop1
li $v0,4
la $a0,output
syscall
la $a1,array
li $t1,10
loop2:
li $v0,1
lw $a0,0($a1)
syscall
li $v0,4
la $a0,spacee
syscall
add $a1,$a1,4
addi $t1,$t1,-1
bnez $t1,loop2
li $v0,10 #exit
syscall
I'm writing MIPS program that will examine a list of 10 numbers to be input from the terminal. And these numbers will output on the terminal in an ascending order. And below are my MIPS program...please can someone help me look into it, because i m running and isn't working proply....
.data
array: .space 40
prompt: .asciiz "Enter a number: "
spacee: .asciiz " "
output: .asciiz "The numbers are: "
.text
main:
li $t1,10
la $a1,array
loop:
addi $t1,$t1,-1
li $v0,4
la $a0,prompt
syscall
li $v0,5
syscall
sw $v0,0($a1)
addi $a1,$a1,4
bnez $t1,loop
li $t1,9
li $t2,9
la $a1,array
loop1:
beqz $t2,here
addi $t2,$t2,-1
lw $t5,0($a1)
lw $t6,4($a1)
add $a1,$a1,4
ble $t5,$t6,loop1
sw $t5,0($a1)
sw $t6,-4($a1)
bnez $t2,loop1
here:
la $a1,array
addi $t1,$t1,-1
add $t2,$t2,$t1
bnez $t1,loop1
li $v0,4
la $a0,output
syscall
la $a1,array
li $t1,10
loop2:
li $v0,1
lw $a0,0($a1)
syscall
li $v0,4
la $a0,spacee
syscall
add $a1,$a1,4
addi $t1,$t1,-1
bnez $t1,loop2
li $v0,10 #exit
syscall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果用addi代替add,可以吗? 此外,对于汇编,它有时有助于进行大量注释,因为它的阅读方式与自然语言不相近。
我没有 MIPS 处理器,但这可以在 C 中运行:
#include“stdafx.h”
If you use addi instead of add, does it work? Also with assembly, it sometimes helps to comment a lot since it doesn't read anywhere close to a natural language.
I don't have a MIPS processor, but this worked in C:
#include "stdafx.h"
首先,您使用了一些指令的方式是错误的。
应该是
因为您要添加一个中间寄存器,而不是两个寄存器。
除此之外,您应该看看您的比较逻辑。 这是相当混乱且容易出错的。
To begin with, you are using some instructions the wrong way.
should be
Because you are adding an inmediate,not two registers.
In addition to that, you should take a look to your comparing logic. It's quite confusing and error prone.