(Solved) : Using Min Max Code Lab Starting Point Write Implement Mips Program Performs Sort Array Fol Q42778571 . . .

Using the min-max code from the lab as a starting point, writeand implement a MIPS program which performs a sort of an array,with the following considerations:

The array is to be sorted by insertion sort, not selection sort.For details of the algorithm, seehttp://en.wikipedia.org/wiki/Insertion_sort;

The array is to be stored in doublewords, not words;

The array is to be sorted by absolute value (e.g. 1, -2, 3, -4,5, -6…) but the values of the array elements themselves shouldnot be changed; and

Use at least one subroutine which makes use of a stack frame,including frame offsets for argument or return value access.

Bonus: provide a visual interface showing the progress of thesearch at each step.

UPDATE: doubleword and absolute value features are nowconsidered bonuses rather than key requirements. You must stillperform an insertion sort and you must still use a stack frame foryour subroutine.

#### Program Name: min-max.s #### – will print out the minimum value min ## – and the maximum value max of an array.## ## – Assume the array has at least two elements (a[0] and a[1]). ## – It initializes both min and max to a[0] and then## – goes through the loop count – 1 times.## – This program will use pointers.## #### t0 – point to array elements in turn## t1 – contains count of elements## t2 – contains min## t3 – contains max## t4 – each word from array in turn#################################################### ## text segment ## ################################################## .text .globl __start__start: # execution starts here la $t0,array # $t0 will point to the elements lw $t1,count # exit loop when $t1 == 0 lw $t2,($t0) # initialize min = a[0] lw $t3,($t0) # initialize max = a[0] add $t0,$t0,4 # pointer to start at a[1] add $t1,$t1,-1 # and go round count – 1 times loop: lw $t4,($t0) # load next word from array bge $t4,$t2,notMin # skip if a[i] >= min move $t2,$t4 # copy a[i] to minnotMin: ble $t4,$t3,notMax # skip if a[i] <= max move $t3,$t4 # copy a[i] to maxnotMax: add $t1,$t1,-1 # decrement counter add $t0,$t0,4 # increment pointer by word bnez $t1, loop # continue if counter > 0 la $a0,ans1 # print prompt on terminal li $v0,4 # system call to print syscall # out “min = ” move $a0,$t2 # print result min li $v0,1 syscall la $a0,ans2 # print out “max = ” li $v0,4 syscall move $a0,$t3 # print result max li $v0,1 syscall la $a0,endl # syscal to print out li $v0,4 # a new line syscall li $v0,10 # Exit syscall # Bye!################################################## ## data segment ## ################################################## .data array: .word 3,4,2,6,12,7,18,26,2,14,19,7,8,12,13 count: .word 15 ans1: .asciiz “min = ” ans2: .asciiz “nmax = ” endl: .asciiz “n” #### end of file min-max.s

Using the program available what changes need to be made for thequestion to be correct?

Expert Answer


Answer to Using the min-max code from the lab as a starting point, write and implement a MIPS program which performs a sort of an …

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?