Professor Shai Simonson - CS304 - Computer Architecture


Assignment 3

Assembly Language Using MIPS
Basic Data Structures
Stacks, Arrays, Procedures and Functions

 

Due Monday, October 22.  (40 points)

0.  In the book - Chapter 2:   30, 37, 38, 51.

1.  What is the address of element 36 (assuming you start counting at 1) of a 45-element array that starts at memory location 40 if the elements are:
      a. characters    b. integers    c. 7-byte structs    d. 10 character strings

2.   A 12 by 11, 2-dimensional array, has its first row and column numbered 0,0.  The base address is 1000, and each element is a word.  What is the byte address of element [8,10] assuming row-major form? What is the byte address of element [8,10] assuming column-major form?

3. Write a SPIM program that takes 48 integers hard-coded into the data section, and prints them out row by row assuming the 48 numbers are stored as a 6 by 8 two dimensional array of integers in
(a) row-major form, and
(b) column-major form.
    For example, if the array were 2 by 3, and the numbers were:  1, 2, 3, 4, 5, 6.  Then your output would be:
       Row-major order
       1   2   3
       4   5   6
    Column-major Order
       1   3   5
       2   4   6

4. Using an array to implement a stack, write a SPIM function that takes a string in postfix notation and returns its value when executed.  The string should contain only single digits, and the symbols * or +.   The function should return -1 if the input contains illegal symbols, and -2 if the input has all legal symbols but is not  in correct postfix form.   For example: 897*6++, should return 77 (i.e. 8+ (63+6)), 7**78+ is not in correct postfix form and should return -2 error code, and 7a+62 contains "a" and should therefore return a -1 error code.   The stack will help you check for error condition -2.  We will review the algorithm for this in class.  Write a SPIM program that reads in a string, calls the function, and prints an appropriate message based on the output of the function.

back

 


shai@stonehill.edu

http://www.stonehill.edu/compsci/shai.htm