1. Setup. Use assembler directives to allocate spaces in memory to hold three integer arrays A, B, and C. Each has a maximum of 10 4-byte integers.

2. Input. Prompt the user for the size of the arrays (assuming that the user inputs a size no more than 10). And then prompt the user the input arrays A and B. Use the subroutine mentioned below to let the user input the integers for each array.

3. Calculation. Calculate the sum C = A + B (i.e., vector sum) by calling the subroutine mentioned below. Store the results in the space you allocated in memory for the array C.

4. Output. Use the subroutine mentioned below to print out the array C.

5. Required subroutines:

a. 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. 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. 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.

Here is what I worked on so far:

#data segment .data numbers:.word 2,1,5,3,10 count: .word 5 ans1: .asciiz "sum = " endl: .asciiz "\n" #text segment .text main: la $a0, numbers # load array address lw $a1, count # load number of elements jal sum # call sum function move $a0, $v0 # call print jal print j finish # finish sum: bge $t2, $a1, done #if t2>=$a1, goto done lw $t0, 0($a0) #load value at addr a0 to t0 add $t1, $t1, $t0 # sum = sum + array[i] addi $a0, $a0, 4 # add addr by 4 to get the address of next value in the array addi $t2, $t2, 1 # i = i + 1 j sum done: move $v0, $t1 # move result to v0 jr $ra #go to return addr print: # code to print ansl, sum and end # deleted for brevity jr $ra # return finish: li $v0, 10 # exit syscall

The output is supposed to look something like this:

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

This post has been edited by **macosxnerd101**: 31 October 2012 - 07:24 PM

Reason for edit:: Please use code tags