Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In MIPS Assembly Language. Focus: Static arrays, dynamic arrays, subprograms. Objectives: You will write a program that will add the values of two arrays together

In MIPS Assembly Language.

Focus:

Static arrays, dynamic arrays, subprograms.

Objectives:

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
    • 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 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 whats 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). Failure to do so will lose you points in your program!

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

Sample output:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions