CS 354, version B
Fall 2008
Name:___________________
ID:___________________
Exam 3
No electronic devices may be used while taking this exam. Examples of devices not allowed are calculators, pagers, cell phones, wrist calculators/computers, laptop computers, pocket computers. Each student is allowed one 8.5 by 11 inch sheet of paper with handwritten notes. The notes may be on both sides of the paper. Show all work, and do any/all calculations on the exam. Extra scratch paper may not be used.

The end of the exam has tables of TAL and MIPS machine language instructions.

Exam Score
Q1 = _____ / 12
Q2 = _____ /   8
Q3 = _____ / 10
Q4 = _____ /   8
Q5 = _____ / 12
Total = _____ / 50



Question 1 (12 points = #(Correct) - #(Incorrect) + 0*#(Left Blank) with a minimum score of 0)
Consider rows for different actions. Consider one column for hardware's initial reaction to an exception and another for the actions of a non-reentrant software exception handler (kernel) (e.g., from Assignment 6).

Enter Y for yes in a table entry if its action is (sometimes) performed by the entity specified by the column. Enter N for no if the action is never performed. Example: Since hardware writes the EPC on an exception and the kernel must update the EPC on a syscall, we have filled in two boxes for you.


+------------------------------------------+---------------+---------------+
|                                          | HW's Reaction | NON-Reentrant | 
| Action                                   | to Exception  |   SW Kernel   |
+------------------------------------------+---------------+---------------+
| Writes Exception Program Counter (EPC)   |       Y       |       Y       |
+------------------------------------------+---------------+---------------+
| Reads  Exception Program Counter (EPC)   |       N       |       Y       |
+------------------------------------------+---------------+---------------+
| Writes Exception Code (in Cause reg.)    |       Y       |       N       |
+------------------------------------------+---------------+---------------+
| Reads  Exception Code (in Cause reg.)    |       N       |       Y       |
+------------------------------------------+---------------+---------------+
| Disables All Interrupts                  |       Y       |       N       |
+------------------------------------------+---------------+---------------+
| Enables  All Interrupts                  |       N       |       N       |
+------------------------------------------+---------------+---------------+
| Reads Previous Kernel/User Mode (Status) |       N       |       N       |
+------------------------------------------+---------------+---------------+

Question 2 (8 points )
(a) What is temporal locality? What is spatial locality?

Temporal locality is the tendency to re-reference items recently referenced.

Spatial locality is the tendency to re-reference items spatcially near recently referenced items.





(b) Give two different reasons that most computer systems include virtual memory.
Protection among processes
Hiding physical memory size for application programmers
Allows all applications to start at the same address (no relocation)
Allow fast start (without load whole program and data)










Question 3 (10 points )
(a) (4 points) Translate the base ten number -37 into normalized binary scientific notation (where the significand, base, and exponent are all in base two).

-100101
-100101 * 2^0
-1.00101 * 2^5













(b) (6 points) Translate the base ten number -37 into IEEE Single-Precision Floating Point. Show your final answer in hexadecimal. (Recall: 1-bit sign, 8-bit biased-127 exponent, and 23-bit fraction with the most-significant bit implicit.)



-1.00101 * 2^5
S = 1
E = 5+127 + 132 = 10000100
F = 00101

1 10000100 00101 00 0000 0000 0000 0000
1100 0010 0001 0100 0000 0000 0000 0000
0xc2140000


Question 4 (8 points)
(a) (2 points) Translate the following MAL code into TAL (not MIPS machine language). Assume that datum is placed at address 0x00ee0066


       sb $7, datum

       lui $1, 0x00ee
       sb  $7, 0x0066($i)






(b) (6 points) Translate your TAL code from part (a) into MIPS machine language code. Show your final answer in hexadecimal.

0011 1100 000t tttt iiii iiii iiii iiii # lui $1, 0x00ee
0011 1100 0000 0001 0000 0000 1110 1110 # ttttt = 00001; iii...i = 0.... 1110 1110
0x3c0100ee

1010 00bb bbbt tttt iiii iiii iiii iiii # sb $7, 0x066($1)
1010 0000 0010 0111 0000 0000 0110 0110 # bbbbb = 00001; ttttt = 00111 ; iii + .. 0110 0110
0xa0270066









Question 5 (12 points)
(a) (8 points) Translate the following I/O-related MIPS machine language back to TAL.


      0x2002000c

      0010 0000 0000 0010 0000 0000 0000 1100
      0010 00ss ssst tttt iiii iiii iiii iiii
      addi $2, $0, 12




      0x0000000c

      0000 0000 0000 0000 0000 0000 0000 1100
      syscall







      0x00406020

      0000 0000 0100 0000 0110 0000 0010 0000
      0000 00ss ssst tttt dddd d000 0010 0000
      add $12, $2, $0






(b) (4 points) Translate your TAL code from part (a) back into a single MAL instruiction.
getc $12



































ADD TABLES OF TAL INSTRUCTIONS (page 1 of 2)

http://www.cs.wisc.edu/~markhill/cs354/Fall2008/handouts/TALscanned.pdf



































































ADD TABLES OF TAL INSTRUCTIONS (page 2 of 2)