← Back to problems
UNSW COMP1521 · medium

COMP1521 2022T2 Q4 — MIPS arrays

COMP1521 2022T2 Q4 · 10 marks · MIPS Topic: MIPS arrays · Source: https://cgi.cse.unsw.edu.au/~cs1521/26T1/resources/practice_exams.html

Summary: Length of the longest strictly increasing run in an array

You have been given 22t2final_q4.s , a MIPS program that currently reads 10 numbers and then prints 42 .

Your task is to modify 22t2final_q4.s so that it is equivalent to this C program:

// Reads 10 numbers into an array // Prints the length of the longest sequence // of strictly increasing numbers in the array.

#include <stdio.h>

int main ( void ) { int i ; int numbers [ 10 ] = { 0 };

i = 0 ; while ( i < 10 ) { scanf ( "%d" , & numbers [ i ]); i ++ ; }

int max_run = 1 ; int current_run = 1 ; i = 1 ; while ( i < 10 ) { if ( numbers [ i ] > numbers [ i - 1 ]) { current_run ++ ; } else { current_run = 1 ; }

if ( current_run > max_run ) { max_run = current_run ; }

i ++ ; }

printf ( "%d \n " , max_run );

return 0 ; }

The program 22t2final_q4.c returns the length of the longest consecutive sequence of strictly increasing numbers.

For example:

1521 mipsy 22t2final_q4.s 1 2 3 4 5 6 7 8 9 10 10 1521 mipsy 22t2final_q4.s 1 2 3 4 5 6 7 7 8 9 7 1521 mipsy 22t2final_q4.s 1 2 3 1 2 4 5 5 6 6 4 1521 mipsy 22t2final_q4.s 10 9 8 7 6 5 4 3 2 1 1

You can use make(1) to build the provided C code:

make 22t2final_q4

You can use 1521 mipsy to run your MIPS code:

1521 mipsy 22t2final_q4.s

Your program can assume that all integers will fit in a MIPS register.

You may define and call your own functions if you wish.

Your solution must be in MIPS only.

Your solution must not be in C , C++ , Python , or any other language.

No error checking is necessary or required.


🤖 Write MIPS (mipsy). Read exactly 10 integers; print the length of the longest run of strictly increasing consecutive values (minimum 1).

Verified on the sandbox AND cross-checked against an independent oracle (official examples included).

MIPS (mipsy)