Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a MIPS code that sorts input of numbers into an array in order and then calculates mean median mode. What I need is

I have a MIPS code that sorts input of numbers into an array in order and then calculates mean median mode. What I need is a piece of code to be added, after the mean median mode is outputted, that can ask the user for a first and last name until the user manually exits and then orders the names in alphabetical order.

Here is the code I have:

#Define data .data

#Define space nmbrs: .space 36

#Mean prompt mean: .asciiz "Mean Value= "

#Median prompt median: .asciiz "Median Value= "

#Mode prompt modePrompt: .asciiz "Mode Value= "

#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 li $s0,0 li $s1, 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 addi $s0,$s0,1

#Add instruction addi $t0,$t0,4

#Store sw $v0, ($a1)

#Add addi $a1, $a1, 4

#Jump j loop

#Define Sort 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) add $s1,$s1,$a0 syscall la $a0, nxtLne li $v0, 4 syscall addi $a1, $a1, 4 addi $t0, $t0, -4 j loop1 #Define method done: #Mean display la $a0,mean #mean prompt li $v0,4 syscall mtc1 $s0, $f0 #count of the numbers in the array cvt.s.w $f1, $f0 mtc1 $s1, $f0 #convert into float cvt.s.w $f0, $f0 div.s $f12,$f0,$f1 #sum/count li $v0,2 #display mean syscall #nextline la $a0, nxtLne li $v0, 4 syscall #Median display rem $t3,$s0,2 #check odd or even to find remainder beq $t3,0,even #remainder 0 when the count of the numbers in the array is even #odd the find middle value div $t3,$s0,2 addi $t3,$t3,1 li $t0,0 la $a1,nmbrs loop2: beq $t0,$t3 oddMedian lw $a0, 0($a1) addi $a1, $a1, 4 addi $t0, $t0,1 j loop2 oddMedian: move $t0,$a0 la $a0,median li $v0,4 syscall move $a0,$t0 li $v0,1 syscall j mode #Even number median = (middle1+middle2)2 even: div $t3,$s0,2 addi $t3,$t3,1 li $t0,0 la $a1,nmbrs loop3: beq $t0,$t3 evenNext lw $a0, 0($a1) addi $a1, $a1, 4 addi $t0, $t0,1 j loop3 evenNext: move $s3,$a0 li $t0,0 div $t3,$s0,2 addi $t3,$t3,1 li $t0,0 la $a1,nmbrs loop4: beq $t0,$t3 evenMedian lw $a0, 0($a1) addi $a1, $a1, 4 addi $t0, $t0,1 j loop4 evenMedian: move $t4,$a0 la $a0,median li $v0,4 syscall add $a0,$t4,$s3 mtc1 $a0, $f0 cvt.s.w $f12, $f0 li $t5,2 mtc1 $t5, $f1 cvt.s.w $f1, $f1 div.s $f12,$f12,$f1 li $v0,2 syscall #mode finding step #mode is the maximum count value mode: li $s3,0 #maxvalue li $s4,0 #max count li $t0,0 li $t2,0 la $a1,nmbrs la $t5,nmbrs

fLoop: beq $t0,$s0,exit li $t1,0#counter lw $a2,0($t5) addi $t0,$t0,1 addi $t5,$t5,4 sLoop: beq $t2,$s0,countSet lw $a0,0($a1) bne $a0,$a2,nextVal addi $t1,$t1,1 addi $a1,$a1,4 addi $t2,$t2,1 j sLoop nextVal: addi $a1,$a1,4 addi $t2,$t2,1 j sLoop countSet: ble $t1,$s4,fLoop move $s4,$t1 move $s3,$a2 j fLoop #display mode and exit exit: #Nextline la $a0, nxtLne li $v0, 4 syscall #Mode prompt la $a0,modePrompt li $v0,4 syscall #display result move $a0,$s3 li $v0,1 syscall #end of the program li $v0,10 syscall

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions