• Home
  • Blog
  • CPS250: Programming Assignment about MIPS

CPS250: Programming Assignment about MIPS

0 comments

For this and all programming assignments for this course, you are to write a MIPS assembly language

program that can be loaded and executed using the MARS simulator.

Arrays and Functions

For this assignment, you’ll be writing two functions. Below are the C++ signatures for the functions., as

well as a brief explanation of each.

void arprt(int arr[], int size, int perln) – Given the array arr having the given

size, display the values in the array. A newline should only be output for every perln values displayed,

and following the last value. Values displayed on the same line should be separated by a space. In other

words, output the values in the array, perln values per line of output.

int expos(int arr[], int size, int dest[]) – Given the array arr having the given

size, and an array dest that is at least as large as arr, copy from the arr array into the dest array only

those values in arr that are greater than zero. Return the number of values that were copied into dest.

Your functions are expected to adhere to the standard MIPS conventions for parameter passing,

returning values, and protecting registers used in the function.

Your main program will call upon these functions to process four arrays. These arrays will be defined

as follows:

.data

.align 2

.eqv size1,9

nums1: .word 12,­13,25,66,102,­111,­234,53,26

.eqv size2,12

nums2: .word ­44,55,22,­33,44,­77,77,44,33,99,21,­99

.eqv size3,6

nums3: .word ­21,­32,­44,­112,­43,­99

pos: .space 48

Your main program will mainly just make function calls, as follows (shown in C++):

int nsize;

cout << “nums1:n”);

arprt(nums1,size1,4);

nsize = expos(nums1,size1,pos);

cout << “npositive values:n”);

arprt(pos,nsize,4)cout << “nnums2:n”);

arprt(nums2,size2,5);

nsize = expos(nums2,size2,pos);

cout << “npositive values:n”);

arprt(pos,nsize,5)

cout << “nnums3:n”);

arprt(nums3,size3,1);

nsize = expos(nums3,size3,pos);

cout << “npositive values:n”);

arprt(pos,nsize,1)

If your function is working correctly, your output should begin like this:

nums1:

12 ­13 25 66 

102 ­111 ­234 53 

26

positive values:

12 25 66 102

53 26

… (etc. for nums2 and nums3)

You are expected to follow all MIPS conventions for functions.

• Parameters are passed using the $a registers ($a0 is first parameter, etc.).

• Arrays are passed by reference. (Pass the base address of the array.)

• Register $v0 is used to provide the return value to the caller.

• The “jal” instruction is used to make the actual function call.

• The “jr $ra” instruction is used to return to the caller.

• Any registers (other than $t registers and $v0) changed inside the function, should be saved on

the stack on entry and restored on return.

It is important to realize that, since what is being passed to these functions is the base address of the

arrays, you can think of this as simply a pointer to the first element. You can then use pointer

manipulation, rather than indexing, to visit each element in the arrays. 

You may want to review the example “ArraySumPointersFunction” you can find on attachment.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}