Question
I have a piece of MIPS code that will sort any numbers in order inputted from user. I need help however getting the arranged array
I have a piece of MIPS code that will sort any numbers in order inputted from user. I need help however getting the arranged array to then calculate the mean, median, and mode.
Here is the code i currently have
#Define data
.data
#Define space
nmbrs: .space 36
#Define message
msg1: .asciiz "Enter value: 1111 for exit "
#Define message
msg2: .asciiz "The array : "
#Define newline
nxtLne: .asciiz " "
#Define text
.text
#Define main
.globl main
#Main
main:
#Load nmbrs
la $a1, nmbrs
#Load
li $a2, 9
#Set counter
li $t0, 0
#Load exit condition
li $t1,1111
#Loop
loop:
#Display message
la $a0, msg1
#Load
li $v0, 4
#System call
syscall
# Store
li $v0, 5
#System call
syscall
#Branch
beq $v0,$t1,sort
#Add instruction
addi $t0,$t0,4
#Store
sw $v0, ($a1)
#Add
addi $a1, $a1, 4
#Jump
j loop
#Define method
sort:
la $t4, nmbrs
la $t1, nmbrs
addi $t1,$t1,4
la $t8,nmbrs
add $t8,$t0,$t8
la $t9,nmbrs
add $t9,$t0,$t9
addi $t9,$t9,-4
#Define method
lps: lw $t2,($t4)
lw $t3,($t1)
blt $t2,$t3,next
sw $t3,($t4)
sw $t2,($t1)
#Define method
next: addi $t1,$t1,4
blt $t1,$t8,lps
addi $t4,$t4,4
move $t1,$t4
addi $t1,$t1,4
blt $t4,$t9,lps
#Define method
prntArry:
la $a1,nmbrs
la $a0, msg2
li $v0, 4
syscall
#Define method
loop1:
blez $t0, done
li $v0, 1
lw $a0, 0($a1)
syscall
la $a0, nxtLne
li $v0, 4
syscall
addi $a1, $a1, 4
addi $t0, $t0, -4
j loop1
#Define method
done:
j done
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started