M Trouble Program Goal Iterate Array Add Even Values Together Run Program Hangs Don T Know Q37104037

I’m having trouble with my program. My goal is to iteratethrough the array and add only the even values together. When I runthis program it hangs and I don’t know why.

   .text
   .globl main

main:

   lui $16,0×1000
   lw $17,0($16)
addiu $16, $16, 0
   addiu $18, $0, 2
   addiu $19, $0, 28
  
loop:
beq $16, $19, exit
   div $17, $18
   mfhi $13
   beq $13, $0, even
   addiu $16, $16, 4
   j loop
  
even:

   add $10, $10, $17
addiu $16, $16, 4
  
   j loop

exit:

  
.data
   size: .word 8
   array: .word 23, -12, 45, -32, 52, -72, 8, 13


Answer


C Code to Sum up Even values in an array:

#include<stdio.h> int main() int size-8; int a[101 23, -12, 45, -32, 52, 72, 8, 13,i, sum-0; for(i-0; i<size; i++) if(a[i]%2-

MIPS

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.