Question
Ive some code but i just dont know how to put it together im lost when it comes to MIPS the instructions are the following
Ive some code but i just dont know how to put it together im lost when it comes to MIPS the instructions are the following
Write a program that first prints out a header put this on the header:
Name : Anonymus
Project 2 BubbleSort
Then ask the user how many number would they like to enter then ask what numbers would they like to enter and store them in an array (this code is already done but i dont know how to put it together.The code is below. In the bubble sort it ask the user for the size and then for the numbers)
Then display a menu option
Press 1 if you want to bubblesort that array in ascending order ( this code is already done but i dont know how to put it together in a menu option. The code is below)
Press 2 if you want to bubblesort that array in descending order
Press 3 if you would like to find the max value
Press 4 if you would like to find the min value
Press 5 if you would like to find the average of all the values in the array. Result in float if possible
Press 6 if you would like to find a specific number ask the user for the key and tell if it is in the array or not if it is at what index.( this code is already done but i dont know how to put it together in a menu option.The code is below)
Press 7 to exit the program
This program should be written in MIPS ASSAMBLE it should be able to run in SPIM
download this program and try to run it there and see if it works:https://courses.missouristate.edu/KenVollmar/mars/download.htm
the program is called MARS 4.5
---------------------------------------------------------------------------------------CODE------------------------------------------------------------------------------------------------------------------------------------------------
Ive this code for search:
#data declaration section .data #array space declaration array: .space 100 #element asking prompt element: .asciiz "Enter element in array(exit press -1): " #Search element prompt elementSearch: .asciiz "Enter element to search: " #result print prompt Result: .asciiz " found at index " Result1: .asciiz " Not Found" #Main Method .text #counter for array li $s0,0 #load address of array la $a0,array #call array elements enter function jal arrayFill #prompt for read search value la $a0,elementSearch li $v0,4 syscall #read search val li $v0,5 syscall #move into a1 move $a1,$v0 #load address of array la $a0,array #call search function jal search #end of the program li $v0,10 syscall #function to fill array arrayFill: #array base address move $t0,$a0 #prompt array enter la $a0,element li $v0,4 syscall #read user inpout and fill into array li $v0,5 syscall #read user inpout and fill into array loop loop: beq $v0,-1,retArrayFill #counter increment addi $s0,$s0,1 #store value into array sb $v0,0($t0) #prompt array enter la $a0,element li $v0,4 syscall #read user inpout and fill into array li $v0,5 syscall #increment array index addi $t0,$t0,1 #loop continue j loop #return from function retArrayFill: #return to main jr $ra #Function to search user entered elemnt search: #move array address into to move $t0,$a0 #index register li $t2,0 #Search loop loopSearch: #loop continue unti ened of the array beq $s0,0,notFound #each element in t1 lb $t1,0($t0) #check each value beq $t1,$a1,exit #increment index addi $t2,$t2,1 #Increment address addi $t0,$t0,1 #decrement counter addi $s0,$s0,-1 j loopSearch #if elemnt found exit: #display search element move $a0,$a1 li $v0,1 syscall #display result found prompt la $a0,Result li $v0,4 syscall #display index move $a0,$t2 li $v0,1 syscall #return from function jr $ra #If not found notFound: #display search element move $a0,$a1 li $v0,1 syscall #display result not found prompt la $a0,Result1 li $v0,4 syscall #return from function jr $ra
---------------------------------------code----------------------------------------
This is code for bubble sort in ascending order ask the user for the array size and then for the numbers:
.data .align 4 Table: .space 100 msg1: .asciiz "Enter integer: " msg2: .asciiz " " msg3: .asciiz " Sorted array is : " msg4: .asciiz "Enter array size : " .text .globl main main:
#prompt for number of integer li $v0,4 la $a0,msg4 syscall li $v0,5 syscall add $s0,$v0,$zero
sub $s0,$s0,1 #sub one as array is zero based index
#addi $s0,$zero,6 addi $t0,$zero,0 in: li $v0,4 la $a0,msg1 syscall li $v0,5 syscall add $t1,$t0,$zero sll $t1,$t0,2 add $t3,$v0,$zero sw $t3,Table ( $t1 ) addi $t0,$t0,1 slt $t1,$s0,$t0 beq $t1,$zero,in
la $a0,Table addi $a1,$s0,1 #a1=6 #call buble_sort jal buble_sort
#print table li $v0,4 la $a0,msg3 syscall la $t0,Table #s0=5 add $t1,$zero,$zero printtable: lw $a0,0($t0) li $v0,1 syscall li $v0,4 la $a0,msg2 syscall addi $t0,$t0,4 addi $t1,$t1,1 slt $t2,$s0,$t1 beq $t2,$zero,printtable
li $v0,10 syscall
buble_sort: #a0=address of table #a1=sizeof table add $t0,$zero,$zero #counter1( i )=0
loop1: addi $t0,$t0,1 #i++ bgt $t0,$a1,endloop1 #if t0 < a1 break;
add $t1,$a1,$zero #counter2=size=6 loop2:
bge $t0,$t1,loop1 #j < = i
#slt $t3,$t1,$t0 #bne $t3,$zero,loop1
addi $t1,$t1,-1 #j--
mul $t4,$t1,4 #t4+a0=table[j] addi $t3,$t4,-4 #t3+a0=table[j-1] add $t7,$t4,$a0 #t7=table[j] add $t8,$t3,$a0 #t8=table[j-1] lw $t5,0($t7) lw $t6,0($t8)
bgt $t5,$t6,loop2
#switch t5,t6 sw $t5,0($t8) sw $t6,0($t7) j loop2
endloop1: jr $ra
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