Dec 2, 2017 08:30 PM
(This post was last modified: Dec 2, 2017 08:31 PM by ArmDealer.)
Started learning MIPS but can't seem to get the sorting to work. Anyone wanna help? I've been trying this thing for hours...
Tried so many solutions but it either loops infinitely or prints out the array in weird order.
This is suppose to get users input in floating point # then if they enter in 0.0 it exits. Gutta sort it.
Ignore some comments, I added it to help me remember certain things.
Tried so many solutions but it either loops infinitely or prints out the array in weird order.
This is suppose to get users input in floating point # then if they enter in 0.0 it exits. Gutta sort it.
Code
.data
max: .word 24
FPNum: .word 0x0, 0xff800000, 0x7f800000 # Float-point numbers 0, -Infty and Infty
temp: .word 1
num: .space 96
input1: .asciiz "Enter a number:\n"
output: .asciiz "The array contains the following: \n"
.text
.globl main
main:
la $t0, FPNum
lwc1 $f10, ($t0) # $f10=0.0
lw $t1, temp # loop counter
lw $t2, max # upper bound
la $t0, num # address of array
addi $t5, $zero, 0
addi $t6, $zero, 0
Loop:
# print input prompt
la $a0, input1
li $v0, 4
syscall
# get value from the user
li $v0, 6
syscall
c.eq.s $f0, $f10
bc1t prepareSort
addi $t5, $t5, 1
# move user provided value from $f0 to array
s.s $f0, 0($t0)
# move to the next position in the array, increment loop counter
addi $t0, $t0, 4
addi $t1, $t1, 1
ble $t1, $t2, Loop
prepareSort:
# restore loop counter, and array address for printing
lw $t1, temp
la $t0, num
Sort:
bgt $t4, $t5, prepare
addi $t4, $t4,1
l.s $f1, 0($t0)
l.s $f3, 4($t0)
#addi $t0, $t0, 4
c.lt.s 1,$f1, $f3
bc1f swap
#addi $t0, $t0, 4
ble $t4, $t5, Sort
swap:
la $a0, output
li $v0, 4
syscall
s.s $f1, 4($t0)
s.s $f3, 0($t0)
addi $t0, $t0, 4
#j prepareSort
prepare:
# restore loop counter, and array address for printing
lw $t1, temp
la $t0, num
# print output prompt
la $a0, output
li $v0, 4
syscall
j print_loop
print_loop:
# print number from the array
l.s $f12, 0($t0)
li $v0, 2
syscall
# print space
la $a0, 32
li $v0, 11
syscall
# increment loop counter and move to next value
addi $t1, $t1, 1
addi $t0, $t0, 4
ble $t1, $t5, print_loop

