Computer
Organization and Design
(Textbook. Click for information.)
 CS 2733/2731
 Computer Organization II
 Fall 2004

 Recitation 4
 Loops and Arrays in Mips
    Week 4: Sep 13-17
 Due (on time): 2004-09-22  23:59:59
 Due (late):        2004-09-26  23:59:59

Recitation 5 must be submitted following directions at: submissions on or before
  • 2004-09-22  23:59:59 (that's Wednesday, 22 September 2004, 11:59:59 pm) for full credit.
  • 2004-09-26  23:59:59 (that's Sunday, 26 September 2004, 11:59:59 pm) for 75% credit.

Outline: Write a MIPS program that uses two integer arrays (A and B) of size 10. The program should do that following:


Implementation Notes: You can model your program after the following C program:

Recitation Program (C) C Run and Output
% cat rec5.c
#include <stdio.h>
#include <stdlib.h>

void main(void) {
   int A[10] = { 1,  3,  5,  7,  9,
                11, 13, 15, 17, 19};
   int B[10];
   int N;
   int OldB;
   int i;
   printf("Enter N:");
   scanf("%i", &N);
   if (N < 0 || N > 10) {
      printf("N out of range\n");
      exit(1);
   }
   i = 0;
   OldB = 0;
   while (i < N) {
      B[i] = OldB + A[i];
      OldB = B[i];
      i = i + 1;
   }
   i = 0;
   while (i < N) {
      printf("%i", B[i]);
      printf(" ");
      i = i + 1;
   }
   printf("\n");
}
% rec5
Enter N:10
1 4 9 16 25 36 49 64 81 100 
% rec5 
Enter N:5
1 4 9 16 25 
%lab5
Enter N:0

% rec5
Enter N:-1
N out of range
% rec5 
Enter N:11
N out of range


What you should submit: Refer to the submissions directions and to deadlines at the top of this page. The text file that you submit should first have Your Name, the Course Number, and the Recitation Number. The rest of the file should have the following in it, in the order below, and clearly labeled, including at the beginning the appropriate number 1-2.

  Contents of submission for Recitation 4:

Last Name, First Name; Course Number; Recitation Number (4).

  1. MIPS source code for the program.

  2. Log of runs of the program, using spim and the input data shown above for the separate runs, namely, 10, 5, 0, -1, and 11.


Revision date: 2004-06-27. (Please use ISO 8601, the International Standard.)