assembly - MIPS program in 3 arrays one with the number another to rearrange them in ascending order and another to arrange them in descending order -
i have been practicing mips programming skills, taking class computer architecture , ran problem. these instructions: write mips program that:
- initializes integer array
- sorts elements in ascending order in second array , prints them.
- sorts elements in descending order in third array , prints them....
this have far don't know how populate array 3 descending order numbers
.data array: .space 100 input: .asciiz "enter @ least 4 integers: enter number 999 exit \n" output: .asciiz "the array in ascending order: \n" commas: .asciiz "," .text .globl main main: la $a1, array #loads pointer array $a1 li $a2,9 #loads 9 $a2 li $t0,0 li $t1,999 loops: la $a0, input #loads input text $a li $v0, 4 #loads 4 $v0 (prints string) syscall li $v0, 5 #loads 5 $v0 (read interger) syscall beq $v0,$t1,swap addi $t0,$t0,4 #add 4 $t0, save $t0 sw $v0, ($a1) #stores input array addi $a1, $a1,4 #add 4 $a1, save $a1 j loops swap: la $t4, array #loads array $t4 la $t1, array #loads array $t1 addi $t1,$t1,4 #add 4 $t1, save $t1 la $t8,array #loads array $t8 add $t8,$t0,$t8 #add $t8 $t0, save $t8 la $t9,array add $t9,$t0,$t9 #add $t9 $t0, save $t9 addi $t9,$t9,-4 #subtracts 4 $t9, save $t9 loop: lw $t2,($t4) #load input $t2 lw $t3,($t1) #load input $t3 bgt $t2,$t3,loop1 #if $t2 > $t3, go loops #blt $t2,$t3,loop1 #if $t2 < $t3, go loops sw $t3,($t4) #store $t3 in $t4 sw $t2,($t1) #store $t2 in $t1 loop1: addi $t1,$t1,4 #add 4 $t1, save $t1 blt $t1,$t8,loop #if $t1<$t8, go loop addi $t4,$t4,4 #add 4 $t4, save $t4 move $t1,$t4 addi $t1,$t1,4 #add 4 $t1, save $t1 blt $t4,$t9,loop #if $t4<$t9, go loop print: la $a1,array #loads array $a1 la $a0, output #loads output $a0 li $v0, 4 #loads 4 #v0 syscall loop2: blez $t0, done #if $t0<=0, go done li $v0, 1 #loads 1 $v0 lw $a0, 0($a1) #load inout $a0 syscall la $a0, commas #loads commas $a0 li $v0, 4 #loads 4 $v0 syscall addi $a1, $a1, 4 #add 4 $a1, save $a1 addi $t0, $t0, -4 #subtracts 4 #t0, save $t0 j loop2 done: j done
could please me out?
p.s. comments there guideline myself
Comments
Post a Comment