CS 354, version A
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       |
+------------------------------------------+---------------+---------------+
| Disables All Interrupts                  |       Y       |       N       |
+------------------------------------------+---------------+---------------+
| Enables  All Interrupts                  |       N       |       N       |
+------------------------------------------+---------------+---------------+
| Writes Exception Code (in Cause reg.)    |       Y       |       N       |
+------------------------------------------+---------------+---------------+
| Reads  Exception Code (in Cause reg.)    |       N       |       Y       |
+------------------------------------------+---------------+---------------+
| Reads Previous Kernel/User Mode (Status) |       N       |       N       |
+------------------------------------------+---------------+---------------+

Question 2 (8 points )
(a) Give two different reasons that most computer systems include virtual memory.

Protection of OS and I/O devices
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)





(b) 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.











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

-100011
-100011 * 2^0
-1.00011 * 2^5






(b) (6 points) Translate the base ten number -35 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.00011 * 2^5
S = 1
E = 5+127 + 132 = 10000100
F = 00011

1 10000100 00011 00 0000 0000 0000 0000
1100 0010 0000 1100 0000 0000 0000 0000
0xc20c0000


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 0x00dd0088


       sb $9, datum


       lui $1, 0x00dd
       sb  $9, 0x0088($1)













(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, 0x00dd
0011 1100 0000 0001 0000 0000 1101 1101 # ttttt = 00001; iii...i = 0.... 1101 1101
0x3c0100dd

1010 00bb bbbt tttt iiii iiii iiii iiii # sb $7, 0x088($1)
1010 0000 0010 1001 0000 0000 1000 1000 # bbbbb = 00001; ttttt = 01001 ; iii + .. 1000 1000
0xa0290088




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





      0x00405820
 
      0000 0000 0100 0000 0101 1000 0010 0000
      0000 00ss ssst tttt dddd d000 0010 0000
      add $11, $2, $0







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

getc $11


































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)