Please write a MIPS program. A shell program is pasted below as a template/start
ID: 3743155 • Letter: P
Question
Please write a MIPS program. A shell program is pasted below as a template/starting point.
# This program computes the index at which the maximum value occurs in a
# set of 10 confidence values and stores it at the memory location labeled ClassID.
# If there are two or more indices that have equal maximum values, the LARGER
# index is chosen.
.data
# DO NOT change the following three labels (you may change the initial values):
ConfidenceValues: .word 1, 70, 0, 0, 21, 2, 3, 0, 3, 0
ClassID: .alloc 1
.text
# write your code here...
jr $31 # return to OS
HW1-3: The goal of this part is for you to install MiSaSiM, modify a short assembly program HW1-3-shell.asm, simulate, test and debug it in MiSaSiM. The MiSaSiM simulator can be installed according to the instructions at http://lindawills.ece.gatech.edu/misasim Copy or rename the shell program to HW1-3.asm and modify it to compute the index of the largest integer in the 10 element array whose base is labelled ConfidenceValues. Store the index in the location labeled ClassID. If there are two or more integers with equal maximum value, store the highest index at which the max value occurs. The array contains exactly 10 unsigned integers. Be sure to try multiple test cases by changing the initial values in the array.Explanation / Answer
ScreenShot
----------------------------------------------
Program
# This program computes the index at which the maximum value occurs in a
# set of 10 confidence values and stores it at the memory location labeled ClassID.
# If there are two or more indices that have equal maximum values, the LARGER
# index is chosen.
.data
# DO NOT change the following three labels (you may change the initial values):
ConfidenceValues: .word 1, 70, 0, 0, 21, 2, 3, 0, 3, 0
ClassID: .space 1
.text
# write your code here...
#Load address of the confidence value array
la $a0,ConfidenceValues
#Call function to find index
jal maxIndex
#store value in ClassId
sw $v0,ClassID
#Print index for check
lw $a0,ClassID
li $v0,1
syscall
#End of the program
li $v0,10
syscall
#Function definition
maxIndex:
#Set t2=0 for max value
li $t2,0
#Counter for 10 elements
li $t0,0
#Loop for max element
loop:
beq $t0,10,index
#Each element of the array
lw $t1,($a0)
#check for max
ble $t1,$t2,next
#Get max in t2
move $t2,$t1
#Increment registers for next value and counter
addi $t0,$t0,1
addi $a0,$a0,4
j loop
next:
#Increment registers for next value and counter
addi $t0,$t0,1
addi $a0,$a0,4
j loop
index:
#Set index back ward
li $v0,10
li $t0,1
loop1:
#loop for index
beq $t0,10,return
#Take array element backward
lw $t1,($a0)
#compare for index
bne $t1,$t2,next1
j return
next1:
#Decrement index
addi $v0,$v0,-1
#counter increment
addi $t0,$t0,1
#decrement to get next element
addi $a0,$a0,-4
j loop1
#Return index in v0
return:
jr $31 # return to OS
-----------------------------------
Output
1
-- program is finished running --