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

Does anybody know how to write this program? This is part of an assignement that

ID: 3545049 • Letter: D

Question

Does anybody know how to write this program? This is part of an assignement that I am working on and I really need help! Here's how it works:

Write a MIPS program named that sums two arrays of 4-byte integers. Each array has the same number of elements, with a maximum of 10 elements. The program should have the following parts:

a.   Write a subroutine which accepts two parameters to let the user input the integers for an array. The first parameter should be the base address of the array and the second parameter should be the size of the array.

b.   Write a subroutine which accepts four parameters to let the user input the two integer arrays and calculate the sum of the two arrays (i.e., vector sum) and store the sum in the third integer array. The first and second parameters should be the base addresses of the two arrays to be added; the third parameter should be the base address of the sum array; and the fourth parameter should be the size of the array.

c.   Write a subroutine which accepts two parameters to let the user output the integers in an array. The first parameter should be the base address of the array and the second parameter should be the size of the array.


Input the size of array (up to 10):  4

Input array A.

Element [0] of the array:  2

Element [1] of the array:  -4

Element [2] of the array:  -12

Element [3] of the array:  5

Input array B.

Element [0] of the array:  1

Element [1] of the array:  7

Element [2] of the array:  17

Element [3] of the array:  -23

The sum of A and B is array C with:

Element [0] of the array:  3

Element [1] of the array:  3

Element [2] of the array:  5

Element [3] of the array:  -18


Appropriate and meaningful label names must be used throughout the program. The program must also be generously commented to receive full credit. Any nontrivial line of assembly language code should be commented.


Explanation / Answer

please rate - thanks


any questions ask


    .text
    .globl main

main:  
       la $a0, promptSize
       li $v0,4
       syscall                    #prompt for size
       li $v0,5
       syscall                   #get size
       move $t4,$v0        #save size in t4 for later
       la $a2,A
       la $a3,charA
       jal getInput            #input A
       la $a2,B
       la $a3,charB
       jal getInput             #input B
       la $a1,A
       la $a2,B
       la $a0,C
        move $a3,$t4
       jal addArrays        #C=A+B
       la $a2,C
       jal output
       li $v0,10
       syscall                  #exit
output:
       move $t6,$ra
      move $t0,$zero   #counter
      la $a0, sum   #array prompt
      li $v0,4
      syscall
printnext:
        jal print                #print element
        lw $a0,0($a2)      #get value
       li $v0,1
      syscall                   #and output
       addi $t0,$t0,1            #done?
       bne $t0,$t4,getnext1
       move $ra,$t6
       jr $ra   
getnext1:
        addi $a2,$a2,4           #go to next element
        j printnext

getInput:
      move $t6,$ra
      move $t0,$zero   #counter
      la $a0, prompt    #array prompt
      li $v0,4
      syscall
      move $a0,$a3
      syscall
getLoop:
      jal print            #print element
      li $v0,5
      syscall               #get value
      sw $v0,0($a2)      #and save
       addi $t0,$t0,1      #done?
       bne $t0,$t4,getnext
       move $ra,$t6
       jr $ra
getnext:
        addi $a2,$a2,4     #go to next element
        j getLoop

print:
      la $a0,element
      li $v0,4
      syscall
      addi $t5,$t0,48    #make ascii
      sb $t5,num        #and store
      la $a0,num
      syscall
        jr $ra
addArrays:
       move $t0,$a3     #t0=counter
addLoop:
       lw $t1,0($a1)
       lw $t2,0($a2)
       add $t3,$t1,$t2
       sw $t3,0($a0)        #C=a+b
       addi $t0,$t0,-1        #done
       bgtz $t0,next
       jr $ra
next:
       addi $a1,$a1,4      #go to next elements
      addi $a2,$a2,4
      addi $a0,$a0,4
      j addLoop
   
    .data
A:    .space    40
B:    .space    40
C:    .space    40
promptSize: .asciiz "Input the size of array(up to 10): "
prompt: .asciiz " Input array "
element: .asciiz " Element ["
num: .ascii " "
rest: .asciiz "] of the array: "
sum: .asciiz " The sum of A and B is array C with: "
charA: .asciiz "A "
charB: .asciiz "B "


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