Question: Please help me with this program. Instructions: ? Template: A buggy template for a sorting algorithm is given. You should first debug the code, then
Please help me with this program.
Instructions:
? Template: A buggy template for a sorting algorithm is given. You should first debug the
code, then modify it to include more functions on array of data.
? Total points: 100 points
o Debugging and fixing the errors: 20 points
o Sorting the array : 20 points
o Finding and printing minimum and maximum values: 10 points
o Finding the average: 20 points
o Searching a key: 20 points
o Printing general information as header in output (such as the members of the
group, ....): 10 points
? Software: MARS (MIPS Assembler and Runtime Simulator)
Objectives: To learn how to:
? define, populate and print an array in MIPS
? implement functions to sort an array, find the maximum, minimum and average of the
elements of an array and also search a key in an array.
? debug an assembly code
? modify and adopt an existing assembly code for your application
General info:
There is a buggy template file called BubbleSortTemplate.asm attached to the assignment that it should
be debugged first. Then, it should be modified to include other calculations on arrays based on the
mentioned requirements.
MARS Software:
You can find many tutorial videos on YouTube about how to use MARS. For example, there is a tutorial
series starting from MIPS Tutorial 1 Intro and Mars. Watching few of them help you to know to install and
use it.
Requirements:
1. Input:
? Ask user to input the request:
1. Sort ascending
2. Sort descending
3. Calculate maximum
4. Calculate minimum
5. Find average
6. Search a key
7. Exit
2. Ask user to enter the data (this has been provided in the template)
3. Print out:
1. Header:
i. including general info about the program and developers
ii. The output according to the request
Note: No need to include extra code for validation of the data entered by user.
BubbleSortTemplate.asm code:
.data
msg1: .asciiz " Enter integer values followed by return (-1 terminates input): "
msg2: .asciiz ","
msg3: .asciiz "Bubble Sort"
msg4: .asciiz "#########pass#########"
msg5: .asciiz " "
msg6: .asciiz " Number list has been sorted "
.text
.globl main
main:
move $s0,$gp #get the intial point to save array
addi $t0,1 # $t0 = 1
add $t1,$zero,$zero #
add $t2,$zero,$zero #
add $t3,$zero,$zero #
add $t6,$zero,$zero
add $t4,$zero,$zero
sub $t7,$zero,1 # terminate
li $v0,4 # system call to put the string
la $a0,msg1 #
syscall #
add $s1,$s0,$zero # copy the pointer to array in $s1
entervalues:
li $v0,5 # get the value in v0
syscall #
beq $v0,$t7,bubblesort # end of string run to bubblesort
sb $v0,0($s1) # put the value at the position pointed by $s1
addi $s1,1 # move the $s1 pointer by one
add $t5,$s1,$zero # $t5 stores the end value
j entervalues
bubblesort:
add $t4,$s0,$zero
addi $t6,1
#s1-1 -> s0
sub $s1,$s1,$t0
beq $s1,$s0,ending # we have sorted everything
#s0 -> s1
add $s2,$s0,$zero
loopinterno:
lb $t1,0($s2) # first element
lb $t2,1($s2) # second element
slt $t3,$t2,$t1 #
beq $t3,$zero,proximo #
sb $t2,0($s2) #
sb $t1,1($s2) #
proximo:
addi $s2,1 #
bne $s2,$s1,loopinterno #
li $v0,4 # system call to put the string
la $a0,msg5 #
syscall #
li $v0,4 # system call to put the string
la $a0,msg4 #
syscall #
li $v0,4 # system call to put the string
la $a0,msg5 #
syscall #
imprime:
li $v0,1
lb $a0,0($t4)
syscall
li $v0,4
la $a0,msg2
syscall
addi $t4,1
bne $t4,$t5,imprime
jal bubblesort
ending:
li $v0,4 # system call to put the string
la $a0,msg6 #
syscall #
li $v0,5
syscall
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
