Question: Focus: MIPS(Assembly programming) System stack, dynamic arrays. Objectives: You will write a program that will create an array and perform various tasks with it. The

Focus: MIPS(Assembly programming)

System stack, dynamic arrays.

Objectives:

You will write a program that will create an array and perform various tasks with it. The array length should be between 5 and 15 (inclusive).

Once the array has been created, it should be printed to the console in a readable format. Then you will call a subprogram to sum up all the even values contained in the array, returning this sum and the number of even values (a.k.a. count) back to main. Finally, main will call print_sum_average to calculate the average, then print the sum, count, and average, before returning back to main and terminating the program.

This will require at least 6 subprograms, which are described in more detail below.

create_array:

Inputs a number between 3-10 (inclusive) from the user, then uses two subprograms to allocate an array of that size and fill it with user input. It should call allocate_array after obtaining a valid array length, and then use the length and returned base address to call read_array to prompt the user for values. Once both actions are complete, it sends back both the array base address and the length as arguments back to main.

Arguments IN: none

Arguments OUT:

  • $sp+0: array base address
  • $sp+4: array length

allocate_array:

Creates a dynamic array of the given size.

Arguments IN:

  • $sp+0: array length

Arguments OUT:

  • $sp+4: array base address

read_array:

Reads in a series of integers as user input into the given array.

Arguments IN:

  • $sp+0: array base address
  • $sp+4: 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:

  • $sp+0: array base address
  • $sp+4: array length

Arguments OUT: none

sum_even_values:

Loops through the array and sums up the elements in the array, but only include the ones that are even. It then returns the sum back to main. Do not print the result in this subprogram!

Ex: sum of array [ 2, 5, 17, 8, -1, 6 ] is 16 (2 + 8 + 6)

Arguments IN:

  • $sp+0: array base address
  • $sp+4: array length

Arguments OUT:

  • $sp+8: sum of all even values in the array
  • $sp+12: count of all even values in the array

print_sum_average:

Calculates the average of the even values in the array by dividing the sum by the count passed in, and prints the sum, count, and average before returning to main. If the sum and count are 0, the program should NOT crash!

Arguments IN:

  • $sp+0: sum of all even values in array
  • $sp+4: count of all even values in array

Arguments OUT: none

Program Outline:

  • main
    • create_array
      • allocate_array
      • read_array
    • print_array
    • sum_even_values
    • print_sum_average

Other Requirements:

  • 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, as well as the stack offsets youre using to pass arguments in and out of the subprograms.
  • You must use the stack to pass all of your arguments, in the exact order specified in this document. Failure to do so will lose you points in your program!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!