Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming with MARS IDE Array The purpose of this lab is to introduce you to t

ID: 667117 • Letter: P

Question

Programming with MARS IDE Array

The purpose of this lab is to introduce you to the layout and structure of the Mars IDE development tool in addition to Array programming. In this lab, Data section will be used in the MIPS Assembly language to represent the array elements.

.text
   .globl __start
__start:

la $t0,array # $t0 will point to elements
lw $t1,count # exit loop when $t1 is 0
lw $t2,($t0) # initialize both min ($t2)
lw $t3,($t0) # and max ($t3) to 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 min
notMin: ble $t4,$t3,notMax
# skip if a[i] <= max
move $t3,$t4 # copy a[i] to max
notMax:   add $t1,$t1,-1 # decrement counter
add $t0,$t0,4 # increment pointer by word
bnez $t1,loop # and continue if counter>0
  
#################################################
# #
#       data segment #
# #
#################################################
   . data
array:   . word 3,4,2,6,12,7,18,26,2,14,19,7,8,12,13
count: word 15
##
## end of file

Observe the registers/Memory locations values after each Step Run. Record the final values.

Questions:

What is the final value of $t2?

What is the final value of $t3?

What does the value of $t2 represent?

What are Min and the Max numbers in the array?

Modify this program to find the Min. value only.

Explanation / Answer

What is the final value of $t2?
     
In $t2 we are storing, the minimum value from the array. so Final value in $t2 is 2;

What is the final value of $t3?
I
n $t3 we are storing, the maximum value from the array. so Final value in $t3 is 26;

What does the value of $t2 represent?
Value of $t2 represents the minimum value from the array


What are Min and the Max numbers in the array?
   Min number is 2 and Max number is 26;

Modify this program to find the Min. value only.


__start:   

la $t0,array # $t0 will point to elements
lw $t1,count # exit loop when $t1 is 0
lw $t2,($t0) # initialize both min ($t2)
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 min

notMin:    add $t1,$t1,-1 # decrement counter
add $t0,$t0,4 # increment pointer by word
bnez $t1,loop # and continue if counter>0