University of Wisconsin Computer Sciences Header Map (repeated with 
textual links if page includes departmental footer) Useful Resources Research at UW-Madison CS Dept UW-Madison CS Undergraduate Program UW-Madison CS Graduate Program UW-Madison CS People Useful Information Current Seminars in the CS Department Search Our Site UW-Madison CS Computer Systems Laboratory UW-Madison Computer Sciences Department Home Page UW-Madison Home Page

Homework 3

CS/ECE 354, Fall 2003


Send e-mail questions to Nitin Agrawal, nitina@cs.wisc.edu
Due Wednesday, October 22, before 5 pm.


Homework (34 points total)

  1. (8 points total) Consider a three-dimensional array A of .word's, whose first dimension runs from 1 to 7, second from 1 to 4, and third from 1 to 10. Assume array A is stored beginning at memory address 1000 (base ten). Assume also elements are stored in row major order extended to three dimensions:
    A[1,1,1] is stored first, A[1,1,2] second, ... A[1,1,9], A[1,1,10], A[1,2,1], A[1,2,2], ...
    A[1,3,9], A[1,3,10], A[1,4,1], A[1,4,2], ... A[1,4,9], A[1,4,10], A[2,1,1], A[2,1,2], ...
    A[7,4,9], A[7,4,10].

    (a) How many bytes of storage are required to store array A?

    (b) At what memory address is element A[7,1,10] stored?

    (c) Which element of array A is stored in the memory word just before element A[7,1,10]?

    (d) Which element of array A is stored in the memory word just after element A[7,1,10]?

  2. (8 points total) A stack of characters and a stack pointer variable are declared in SAL with:
    
    sp:        .word
    charstack: .byte  0:256
    
    
    This stack is defined such that as the stack grows, the value in the stack pointer (sp) gets smaller. The stack pointer is also defined to point to the next available place for data (not the currently full location).

    PART A (2 points) Write a SAL code fragment that initializes the stack pointer variable, sp.

    PART B (3 points) Write a SAL code fragment that pushes the character 'Q' onto this stack. The code fragment must also check if the stack is full. If the stack is full, then have the code branch to a location called charstack_full. The code fragment associated with this label is given:
    
    .data
    full_err_str:  .asciiz  "Stack full. Cannot complete push operation."
    .text
    charstack_full: puts  full_err_str
                    done
    
    
    PART C (3 points) Now write a SAL code fragment that pops a value off this stack, and places the value into the .byte variable my_char. If the stack is empty, then have the code branch to a location called charstack_empty. The code fragment associated with this label is given:
    
    .data
    empty_err_str:  .asciiz  "Stack empty. Cannot pop off char stack."
    .text
    charstack_empty: puts  empty_err_str
                     done
    
    
  3. (6 points) What values (in hexadecimal) are in registers $7, $8, and $9 after the follow MAL sequence:
    
    li    $6, 0x3c96
    sll   $7, $6, 20
    sra   $8, $7, 4
    and   $9, $7, $8
    
    
  4. (6 points) Identify the addressing mode of each operand in the following MAL code fragment. (There are 7 operands total, including the result operands.)
    
    sw    $12, ($13)
    
    lw    $3, -12($23)
    
    sra   $11, $9, 6
    
    
  5. (6 points) Implement the following SAL code fragment in MAL. Make sure that the MAL code has exactly the same functionality of the SAL code. Assume that variables alpha and beta have been declared as integers.
    
               bgez alpha, my_gez
               move beta, -1
               b my_end
    my_gez:    bgt alpha, 0 my_gtz
               move beta, 0
               b my_end
    my_gtz:    move beta, 1
    my_end:
    
    

Handing In the Homework

Turn in your file containing answers by running the script:


  handinHW3 hw3file

where hw3file is an example name of a file containing the homework answers. The handinHW script submits your homework for you. No printout will be turned in.