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 4

CS/ECE 354, Fall 2003


Send e-mail questions to Eric Robinson, erobinso@cs.wisc.edu
Due Friday, November 7, before 5 pm.


Homework (53 points total)

  1. (6 points) Procedure A calls procedure B. Procedure A gives 2 arguments to procedure B. Following the MIPS conventions, what is the minimum size of activation record that procedure A could use? What goes into this minimum-sized activation record?

  2. (6 points) Here are two diagrams describing the ordering of parameters within space allocated on the stack for the MIPS architecture.
                     address 0 at the top of this diagram
         |             |<-$sp          |            |<-$sp
         ---------------               --------------
         |     $a0     |               |  param 5   |  ---
         ---------------               --------------    |
         |     $a1     |               |    $a3     |    |
         ---------------               --------------    |
         |     $a2     |               |    $a2     |    |--- space allocated
         ---------------               --------------    |    by procedure A
         |     $a3     |               |    $a1     |    |
         ---------------               --------------    |
         |  param 5    |               |    $a0     |    |
         ---------------               --------------    |
         |     $ra     |               |    $ra     |  ---
         ---------------               --------------
         |             |               |            |
         ---------------               --------------
         |             |               |            |
         ---------------               --------------
         |             |               |            |
         ---------------               --------------
    
    Assume that A calls B, and A gives B 5 arguments. Procedure A then calls C, and A gives C 2 arguments. Using these assumptions, which of these orders (diagram on left or diagram on right) ought to be used? Why?

  3. (4 points) A compiler must assign a local variable within a leaf procedure to reside in a register. On the MIPS, would a $t register or an $s register be chosen? Why?

  4. (4 points) Briefly (1 paragraph or less) justify the existence for register usage and parameter passing conventions for an architecture. (This question is asking why we have conventions.)

  5. (3 points) In MIPS machine code, conditional branch instructions do comparisons of values in registers. Immediate values are not allowed as the operands to be compared. Why?

  6. (12 points) Generate TAL assembly language code for the following MAL code fragment. Assume that variable X is assigned address 0xcc00faa0.
    
    lw   $8, X
    move $9, $10
    putc $11
    rem  $12, $13, $4
    
    
  7. (12 points) Hand assemble the following code section starting at address 0x08040cd0. The addresses are listed for your convenience, you may need more or fewer words of memory than that shown. Show the contents in binary and hexadecimal.
    label1: sb      $10, -20($10)
            la      $12, label1 
            addi    $8, $9, -9
    	j       label1
    
    Address      (contents in hex)   (contents in binary)
    ----------   -----------------  ----------------------------------
    0x08040cd0   0x
    
    0x08040cd4   0x
    
    0x08040cd8   0x
    
    0x08040cdc   0x
    
    


  8. (6 points) The assembler places the machine code for the TAL instruction
    
    bne   $8, $10, while_loop
    
    
    at address 0x0800aa04. The address for label while_loop is assigned to be 0x0800ac00. Give machine code for the branch instruction (in both hexadecimal and in binary). For partial credit, show how you generate the offset field within the branch instruction.

Handing In the Homework

Turn in your file containing answers by running the script:


  handinHW4 hw4file

where hw4file 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.