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

Write a MIPS assembly language program to solve the following problem. For a set

ID: 3601693 • Letter: W

Question

Write a MIPS assembly language program to solve the following problem.


For a set of integers stored in an array, calculate the sum of the positive numbers and the sum of the negative numbers. The program should store both sums in memory variables: posSum and negSum.   Numbers should be read from the array one at a time with a zero value (0) being used to signal the end of data (the zero value is acting as a "sentinel" value).


For examle, if your array has the values: 1010 -510 -3010 1510 2010 -110 -2610 -1810 010, then you program should update the posSum and negSum variables to 4510 and -8010, respectively.


For example, your .data section for the array values: 1010 -510 -3010 1510 2010 -110 -2610 -1810 010, will be:

.data

array: .word 10,-5,-30,15,20,-1,-26,-18, 0

posSum: .word 0

negSum: .word 0
.text

.globl main
main:
# MIPS Assembly language program here
li $v0, 10 # system call to exit the program

syscall


Before you start writing MIPS assembly language, write a high-level language algorithm. THEN, translate it to MIPS assembly language.

Homework #6 Computer Organization Due Oct. 24, 2017 (Tuesday) by 4 PM Write a MIPS assembly language program to solve the following problem. For a set of integers stored in an array, calculate the sum of the positive numbers and the sum of the negative numbers. The program should store both sums in memory variables: posSum and negSum. Numbers should be read from the array one at a time with a zero value (0) being used to signal the end of data (the zero value is acting as a "sentinel value). For examle, if your array has the values: 10 -530 1 20 10-26180 s then you program should update the posSum and negSum variables to 45o and-80, respectively. For example, your.data section for the array values: 10 -5-30o 15 20 1-2610o -1810 0, will be PosSumWord negSum: word 0 .data .word 10,-5,-30,15, 20,-1,-26,-18, 0 word 0 array: .text .globl main main: MIPS Assembly language program here 1i $v0, 10 syscal1 system cali to exit the program Before you start writing MIPS assembly language, write a high-level language algorithm. THEN, translate it to MIPS assembly language. You can download the MIPS simulator at: http://sourceforge.net/projects/spimsimulator/files/ Select the latest version of QISpim for either Windows, MAC or Linux You should submit your homework via the Internet by following the directions at: You need to put the following files in a hw6 folder and zip the folder to create a hw6.zip file. On Windows you can a zip file by right-clicking on the hw6 folder and selecting Sond to|Compressed (zippod) oldor) Your hw6.zip should contain the files: the MIPS assembly language program, e.g., hw6.s from any text-editor (e.g. WordPad) a window capture of the QtSpim simulator after running your assembly language program with the array values: 100-50-3010 15t0 2010 -110-2618r Make sure the array, posSum (showing 45) and negSum (showing -80) are visible in the data section of the sereen capture. You can capture this window by (1) right-clicking anywhere in the window to make it the "currently active window, (2) while holding down the A key, press the

Explanation / Answer

#-------- OUTPUT ---------#

#--------- CODE AND ALGORITHM --------#

# Code to find positive and negative numbers sum in an array
#Data Declarations
.data
array: .word 10, -5, -30, 15, 20, -1, -26, -18, 0

posSumMsg: .asciiz "Positive Sum : "

negSumMsg: .asciiz " Negative Sum : "

newLine: .asciiz " "

posSum: .word 0 # to store positive numbers sum

negSum: .word 0 # to store negative numbers sum

#--
#text/code section
# Basic Algorithm:
# loop through the array accessing each value
# Check if the element is a negative number ( < 0), jump to the block that stores negative sums
# Check if the element is a positive number ( > 0), jump to the block that stores positive sums
# From with each sum block, jump to the loop iteration block so that same number does not get added to both negative and positive sums
# Inside the loop iteration block, verify if the present element is a 0, terminate the loop, else jump to the loop start again
#--

.text

.globl main

main:

# Loop through the array to calculate sum

   la $t0, array # array starting address

   li $t1, 0 # loop index, i=0

   #lw $t2, length # length

   li $t3, 0 # initialize sum=0, for posSum
  
   li $t5, 0 # initialize register for negSum

# this is the main loop where we loop over each array element, till we find a 0 which marks ends of array
sumLoop:
   lw $t4, ($t0) # get array[i]
  
   blt $t4, 0, getNegSum # jump to negative sum calculation block if number < 0
  
   bgt $t4, 0, getPosSum # jump to positive sum calculation block if number > 0

# this block calculates sum for positive numbers
getPosSum:
  
   add $t3, $t3, $t4 # sum = sum + array[i]
  
   j loopback # jumo to the block that handles element access

# this block stores the negative sum
getNegSum:
  
   add $t5, $t5, $t4

# this block takes care of the loopback mechanism for array element access  
loopback:

   add $t1, $t1, 1 # i = i+1
  
   add $t0, $t0, 4 # update array address
  
   bnez $t4, sumLoop # stop the loop if the last element was a 0, else, loop back
  
   # store the sums once all elements have been looped over
   sw $t3, posSum # save sum
  
   sw $t5, negSum
  
   # print a message
   li $v0, 4           # load appropriate system call code into register $v0;
          
   la $a0, posSumMsg
  
   syscall
  
   # print the value
   li $v0, 1
               # code for printing integer is 1
   move $a0, $t3       # move integer to be printed into $a0: $a0 = $t2
  
   syscall  
  
   li $v0, 4           # load appropriate system call code into register $v0;
          
   la $a0, negSumMsg
  
   syscall
  
   li $v0, 1
  
   move $a0, $t5
  
   syscall  
  
   li $v0, 10 # call code for terminate

   syscall # system call

.end main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote