This Assembly is to be sort the 200 array number in assending order.But i don't know what i did wrong in the sort part could anyone can help me with this. THANK YOU
.data
array: .space 800
initstr:
.asciiz "Initial Array: "
finalstr:
.asciiz "Final Array: "
spacestr:
.asciiz " "
newlinestr:
.asciiz "\n"
.text
main:
la $a0, array
addi $a1, $a0, 800
li $s0, 11
li $s1, 106
li $s2, 6075
FillLoop:
mul $s0, $s1, $s0
addi $s0, $s0, 1283
rem $s0, $s0, $s2
sw $s0, 0($a0)
addi $a0, $a0, 4
bne $a0, $a1, FillLoop
la $a1, array
addi $a2, $a1, 800
li $v0, 4
la $a0, initstr
syscall
PrintLoop1:
lw $a0, 0($a1)
li $v0, 1
syscall
la $a0, spacestr
li $v0, 4
syscall
addi $a1, $a1, 4
bne $a1, $a2, PrintLoop1
la $a0, newlinestr
syscall
Sort:
la $a0, array
li $t0, 0
loop1:
li $t1,0
loop2:
lw $s0, 0($a0)
lw $s1, 1($a1)
bgt $s0, $s1, swap
again:
addi $t1, $t1, -1
bgt $t1, $t3, loop1
addi $t0, $t0,1
la $a0, array
bgt $t0, $t3,loop2
swap:
sw $s0, 4($a0)
sw $s1, 0($a0)
j again
la $a1, array
addi $a2, $a1, 800
li $v0, 4
la $a0, finalstr
syscall
PrintLoop2:
lw $a0, 0($a1)
li $v0, 1
syscall
la $a0, spacestr
li $v0, 4
syscall
addi $a1, $a1, 4
bne $a1, $a2, PrintLoop2
la $a0, newlinestr
syscall
.data
array: .space 800
initstr:
.asciiz "Initial Array: "
finalstr:
.asciiz "Final Array: "
spacestr:
.asciiz " "
newlinestr:
.asciiz "\n"
.text
main:
la $a0, array
addi $a1, $a0, 800
li $s0, 11
li $s1, 106
li $s2, 6075
FillLoop:
mul $s0, $s1, $s0
addi $s0, $s0, 1283
rem $s0, $s0, $s2
sw $s0, 0($a0)
addi $a0, $a0, 4
bne $a0, $a1, FillLoop
la $a1, array
addi $a2, $a1, 800
li $v0, 4
la $a0, initstr
syscall
PrintLoop1:
lw $a0, 0($a1)
li $v0, 1
syscall
la $a0, spacestr
li $v0, 4
syscall
addi $a1, $a1, 4
bne $a1, $a2, PrintLoop1
la $a0, newlinestr
syscall
Sort:
la $a0, array
li $t0, 0
loop1:
li $t1,0
loop2:
lw $s0, 0($a0)
lw $s1, 1($a1)
bgt $s0, $s1, swap
again:
addi $t1, $t1, -1
bgt $t1, $t3, loop1
addi $t0, $t0,1
la $a0, array
bgt $t0, $t3,loop2
swap:
sw $s0, 4($a0)
sw $s1, 0($a0)
j again
la $a1, array
addi $a2, $a1, 800
li $v0, 4
la $a0, finalstr
syscall
PrintLoop2:
lw $a0, 0($a1)
li $v0, 1
syscall
la $a0, spacestr
li $v0, 4
syscall
addi $a1, $a1, 4
bne $a1, $a2, PrintLoop2
la $a0, newlinestr
syscall