PLEASE DONT COPY PASTE WRONG ANSWERS! #Lab 2: Finding the minimum of a set of el
ID: 3850026 • Letter: P
Question
PLEASE DONT COPY PASTE WRONG ANSWERS!
#Lab 2: Finding the minimum of a set of elements
Assume that you have an array of 10 elements with base address in $s0. Append to the template code already given the code necessary to find the minimum value from the array (by iterating over the array) and store that value in register $t0.
Note: you are free to use any MIPS assembly instructions or pseudo instructions that are recognized by Spim, but in order to receive full credit you must use a loop.
#Assembler Directives
.data
.word 7
.word 3
.word 17
.word 12
.word 30
.word 2
.word 5
.word 1
.word 16
.word 11
.text
.globl main
#$s0 contains the address of the first
#of the data
main:
lui $s0, 0x1001
ori $s0,$s0,0
Once you have saved the program template, you can write the code, assuming that the base address is in $s0. There are 10 elements to be read, and again, you must find the minimum;
Explanation / Answer
//The necessary MIPS code is written below
//SOURCE POINTER is $t1
#Adding $t1, $s0 and $zero
add $t1, $s0, $zero
#TO load a word from $t0
loop: lw $t3, ($t1)
# Storing the above value to $to
sw $t3, ($t0)
# Now we have to increase the source address by "4"
addi $t1, $t1, 4
# Similarly now we need to increase the destination address by 4
addi $t0, $t0, 4
#The number of bytes we have copied till now is in $t2
subu $t2, $t1, $s0
# To check if the total bytes are 40, we will see the value in $t3
slti $t4, 40 ;
#Repeat the loop
bne $t4, $zero, loop;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.