You will write a program that will add the values of two arrays together
Ask Expert

Be Prepared For The Toughest Questions

Practice Problems

You will write a program that will add the values of two arrays together

Focus: Static arrays, dynamic arrays, subprograms.

Objectives: Write in Mips !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You will write a program that will add the values of two arrays together incrementally to form a new array that contains the sums. All arrays will be printed out to the console when complete, but the summed-up array will be printed backwards using a separate method before the program terminates. The program will start with a static array of eleven fixed integers:

[ 9, 18, 3, 8, 11, 6, 14, 1, 10, 4, 14]

Additionally, you will need two dynamic arrays of the same size: one to read input into and the other to hold the sums of both arrays. So you will need to define three total integer array variables: one static and two dynamic arrays. Since all arrays will be the same fixed size of eleven, no variable is required to hold the array length (i.e. the number of integers it should hold). To do this, we will need four subprograms in addition to the main method.

More details about each subprogram can be found below, along with a general outline of the subprogram calls and some sample output. read_array: Reads in non-negative numbers (i.e. must be >= 0) as user input into an array.

Arguments IN:

• $a0: array base address

• $a1: array length

Arguments OUT: none print_array: Prints each value of an array to the console in a readable format, starting from index 0.

Arguments IN:

• $a0: array base address

• $a1: array length

Arguments OUT: none sum_arrays:

Dynamically allocates an array of eleven integers.

Then it iterates through each array simultaneously, adding together the values of the arrays that were passed in as arguments. The sum of the two numbers (one from each array) should be placed in the newly created array at the same index.

Arguments IN:

• $a0: static array base address

• $a1: dynamic array base address

• $a2: array length

Arguments OUT:

• $v0: base address of array sums print_backwards:

Prints out each value of an array to the console in a readable format, starting from index n – 1, where n = the length of the array.

Arguments IN:

• $a0: array base address

• $a1: array length

Arguments OUT: none Program Outline:

Each subprogram should be called from main:

• Main o o o o o print_array (static array with fixed numbers) read_array print_array (new array with user input) sum_arrays print_backwards (array of sums, created in sum_arrays)

Other Requirements:

• You should start with the skeleton file subprogram_template.s, which can be found under the “Class Files” module on the class homepage. This file contains stubs to subprograms.

• Make sure to write your name, date, a brief description of the program, and a brief description of each subprogram where prompted in the comments.

• You should write some comments as you go along, where appropriate, to indicate what’s happening in your program.

• Fill out the “Registers” section with the registers you used and the purpose for which you used them.

• You must use the proper registers to pass in and out of your subprograms ($a0$a3 to pass in, $v0 and $v1 to pass back to main).

Reminder: When working on MIPS programs, it is recommended to take things one step at a time and test your program as you complete each objective. Doing too much at once can create confusion and make it much more difficult to catch bugs!

For example, here is a recommended approach for this program:

• Print the static array to the console

• Add code to dynamically allocate an array in main and save it to a variable.

• Read in input from the user to fill the new dynamic array

• Print the dynamic array

• Write the sum_arrays subprogram

• Write the print_backwards subprogram

Hints: • Feel free to use the solutions to labs 3 and 4 as guidance.

• You don’t need to use a subprogram to dynamically allocate an array (such as in Lab #4). You can simply create them as you need them: the first in main before calling read_array, and the other in sum_arrays at the start of the subprogram.

• Static arrays can be defined with their values initialized in the .data section, which avoids having to put all of the values in yourself.

• You can loop through all arrays simultaneously, since all will be the same length.

• Upon returning to main from a subprogram, all $a registers and $t registers cannot be assumed to have the same values as they did before the call. If you want to make sure that the correct values get used properly in other parts of the program, you will need to utilize variables to “refresh” your registers. This may require you to re-load values from the variables multiple times in main as you perform each subprogram call.

Hint
EconomicsMIPS is Microprocessor without Interlocked Pipeline Stages. The MIPS assembly language is the assembly language of the MIPS processor. It is a reduced-instruction set architecture and is a very useful language to learn because most of the embedded systems run on the MIPS processor. ...

Know the process

Students succeed in their courses by connecting and communicating with
an expert until they receive help on their questions

1
img

Submit Question

Post project within your desired price and deadline.

2
img

Tutor Is Assigned

A quality expert with the ability to solve your project will be assigned.

3
img

Receive Help

Check order history for updates. An email as a notification will be sent.

img
Unable to find what you’re looking for?

Consult our trusted tutors.

Developed by Versioning Solutions.