I NEED THE ANSWER IN Assembly Language to code in MIPS!!!! Write a function PENO
ID: 3750286 • Letter: I
Question
I NEED THE ANSWER IN Assembly Language to code in MIPS!!!!
Write a function PENO (&X, N, SP, SN) that will find the sum of the positive values and negative values in an array X of length N. "X" the address of an array passed through $a0. "N" is the length of the array passed through $a1. The procedure should return two values,
(1) The sum of all the positive elements in the array passed back through $v0. (
2) The sum of all the negative elements in the array passed back through $v1.
Write a main procedure to call the function PENO (&X, N, SP, SN) to verify your design using the following data set Int X ={-1,2,-3,4,5,6,-7,-8}, and print the sum of the positive values and negative values in X as below .
Cout << “ The sum of the positive values is”;
Cout << v0;
Cout << “ The sum of the negative values is”;
Cout << v1;
Explanation / Answer
.data
array: .word -1,2,-3,4,5,6,-7,-8
msg1: .asciiz " The sum of the positive values = "
msg2: .asciiz " The sum of the negative values = "
.globl main
text
main:
li $v0, 4
la $a0, msg1
syscall
la $a0, array
li $a1, 4
jal peno #call function peno
move $a0, $v0
li $v0, 1
syscall
li $v0, 4
la $a0, msg2
syscall # print the string
li $v0, 1
move $a0, $v1
syscall # print sum of neg
li $v0, 10 # terminate program run
syscall # return control to system
peno:
li $v0, 0
li $v1, 0 # Initialize v0 and v1 to zero
loop:
blez $a1, retzz #If (a1 <= 0) go to return
addi $a1, $a1, -1 # Decrement loop count
lw $t0, 0($a0) # Get values from the array
addi $a0, $a0, 4 # Increment array pointer
bltz $t0, negg # if value is negative send to negg
add $v0, $v0, $t0 # Add to the positive sum
b loop
negg:
add $v1, $v1, $t0 # Add to the neg. sum
b loop
retzz:
jr $ra # Return
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.