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

Please write MIPS assembly language programs using MIPS MARS assembler for the f

ID: 3672855 • Letter: P

Question

Please write MIPS assembly language programs using MIPS MARS assembler for the following question:

Find the smallest of all integers stored in an integer array in memory location starting at “IntArray” (a label in data segment). The integer array values are 0x5, 0x9, 0x4, 0xFF, 0xFE, 0xFA, 0x7, 0x2, 0x8, 0xFD. After finding the greatest integer in the array, store the result in memory location “result” (a label in data segment).

Hint: The data segment of your program will look like this:

IntArray: size: result data .word 0x5,0x9,0x4,0xFFOxFEOxFA,0x7,0x2,0x8,0xFD word 10 .space 4 #initial values of integer array # number of integers in IntArray # declare 4 bytes to hold integer result text # start of text/code segment, write your code below

Explanation / Answer

.data
   IntArray: .word 0x5, 0x9, 0x4, 0xFF, 0xFE, 0xFA, 0x7, 0x2, 0x8, 0xFD
   size: .word 10
   result: .space 4
  
.text
   main:  
  
       la $s1, IntArray   # address to array
       lw $s2, size       # stores array size
       la $s3, result       # result Address
       lw $s4, IntArray   # minValue
      
       li $t0, 0   # start index
       while:   bge $t0, $s2, end
           sll $t1, $t0, 2
           lw $t2, IntArray($t1)
           if:    bge $t2, $s4, endif
               move $s4, $t2
           endif:   addi $t0, $t0, 1
           b while
       end:
      
       sw $s4, result
      
       li $v0, 1
       move $a0, $s4
       syscall
      
       li $v0, 10
       syscall