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

 Take-home Quiz:
 Exceptions
     Due (on time): 2004-11-29  In class
     Due (late):        2004-12-01  In class


Basis for the Quiz: The quiz is based on the following MIPS assembler program, including a very small exception handler. (The line numbers to the left are not part of the code.) Here is the source of the above code without line numbers: with_exception_handler.s

     1  # Program for Review Quiz: With Exception Handler
     2  main:   la      $t1, Data
     3          lw      $t4, 0($t1)
     4          li      $v0, 1          # syscall 1 (print_int)
     5          add     $a0, $0, $t4
     6          syscall
     7          add     $t5, $0, $0
     8          lw      $t6, 0($t5)
     9          li      $v0, 4          # syscall 4 (print_str)
    10          la      $a0, All
    11          syscall
    12          jr      $ra             # return from main
    13          .data
    14  Data:   .word   314159265
    15  All:    .asciiz "\nTh-th-th-that's all folkes!\n"
    16  ############# Start of Exception Handler ######################
    17          .kdata
    18  Inside: .asciiz "  Inside local exception handler\n"
    19          .ktext 0x80000180
    20          li $v0 4        # syscall 4 (print_str)
    21          la $a0 Inside
    22          syscall
    23
    24          mfc0 $k0 $14
    25          addiu $k0 $k0 4
    26          mtc0 $k0 $14
    27          eret
    28  # Standard startup code.  Invoke the routine main with no arguments.
    29          .text
    30          .globl __start
    31  __start: jal main        # start up main
    32          li $v0 10
    33          syscall         # syscall 10 (exit)


Questions: Please submit answers to the following questions by Monday, 29 November 2004, during class. I prefer computer-printed answers, but hand-written answers will also be accepted.

  1. What will happen if just lines 1 through 15 above are run, and without the -notrap option, that is, with

    This code is given below and in without_exception_handler.s. Give the line number of the instruction that causes the exception.

         1  # Program for Review Quiz: With Exception Handler
         2  main:   la      $t1, Data
         3          lw      $t4, 0($t1)
         4          li      $v0, 1          # syscall 1 (print_int)
         5          add     $a0, $0, $t4
         6          syscall
         7          add     $t5, $0, $0
         8          lw      $t6, 0($t5)
         9          li      $v0, 4          # syscall 4 (print_str)
        10          la      $a0, All
        11          syscall
        12          jr      $ra             # return from main
        13          .data
        14  Data:   .word   314159265
        15  All:    .asciiz "\nTh-th-th-that's all folkes!\n"
    

  2. Assume that the entire program is run with the -notrap option, that is, using:

    Starting with line 2, describe exactly what is printed when this code segment executes lines 2 through 12, including possible detours into the code for the exception handler. Will Inside local exception handler be printed and if so, when and why?

  3. What (if anything) is line 27 (eret) doing?

  4. What would happen if the program was executed with the -notrap option (as in item 2.) but with lines 28 through 33 deleted?

  5. What would happen if only line 25 (addiu $k0 $k0 4) were omitted and the program run with the -notrap option?


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