Question: Lab 7-Arrays in MIPS In a High-Level Language, an array is a multi-valued variable: a single array variable can contain many values. Arrays in

Lab 7-Arrays in MIPS In a High-Level Language, an array is amulti-valued variable: a single array variable can contain many values. Arrays in

Lab 7-Arrays in MIPS In a High-Level Language, an array is a multi-valued variable: a single array variable can contain many values. Arrays in MIPS assembly will be similar; however, the abstraction of an array is very much constrained in assembly. In MIPS assembly an array is implemented by storing multiple values in contiguous areas of memory and accessing each value in the array as an offset of the array value. An array is a multivalued variable stored in a contiguous area of memory that contains elements that are all the same size. Allocating Array in Memory In some languages, such as Java, arrays can only be allocated on the heap. Others, such as C/C++ or C#, allow arrays of some types to be allocated anywhere in memory. In MIPS assembly, arrays can be allocated in any part of memory. To allocate an array in static data, a label is defined to give the base address of the array, and enough space for the array elements is allocated. Note also that the array must take into account any alignment consideration (e.g. words must fall on word boundaries). The following code fragment allocates an array of 10 integer words in the data segment. .data array: space 40 Printing an Array This first program presented here shows how to access arrays by creating a PrintIntArray subprogram that prints the elements in an integer array. Two variables are passed into the subprogram, $a0 which is the base address of the array, and $al, which is the number of elements to print. The subprogram processes the array in a counter loop, and prints out each element followed by a ",". The pseudo code for this subprogram follows. Subprogram PrintIntArray(array, size) { print("[") for (int i=0; i < size; i++) { print("," + array[i]) print("]") } Practice Write a program that prompts the user to enter an integer value in an array, and user can also print out some values.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement a program in MIPS assembly that prompts the user to enter integer values into an array and allows printing out some values we need to fol... View full answer

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 Programming Questions!