Docsity

Final Exam Solutions for ECE 3035B - Computing Mechanisms (Fall 2004), Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035B Computing Mechanisms Fall 2004
5 problems, 7 pages Final Exam Solutions 7 December 2004
1
Problem 1 (3 parts, 20 points) Virtual Memory
Answer the following questions for a byte-addressed virtual memory system that uses the
following virtual and physical address formats.
Virtual Address
page number page offset total VA length
28 + 12 = 40
Physical Address
frame number page offset total PA length
20 + 12 = 32
Part A (10 points) Determine the following values:
page size 4 Kbytes
size of virtual address space (byte addressed) 1 Tbytes
size of physical memory (used for frames) 4 Gbytes
number of pages 256 M pages
number of frames 1 M frames
Part B (8 points) Assume the following translations are available in the page table (all values are
in hexadecimal). For each virtual address listed below, determine the corresponding physical
address (if available). Indicate which VAs will result in a page fault given this table.
page number frame number disk location
CAB1234 F6C3 2364514
DE826 111 2836452
35C D3A4B 7665358
DE829 N/A 2754830
DE820 325 3476268
virtual address physical address page fault?
DE8269AC 1119AC N
DE82012 N/A (unallocated) Y
DE829248 N/A (on disk) Y
35CF64 D3A4BF64 N
Part C (2 points) What virtual address would translate to the physical address F6C3358 using
the page table in part B?
Virtual Address: CAB1234358
pf3
pf4
pf5

Partial preview of the text

Download Final Exam Solutions for ECE 3035B - Computing Mechanisms (Fall 2004) and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

5 problems, 7 pages Final Exam Solutions 7 December 2004

Problem 1 (3 parts, 20 points) Virtual Memory

Answer the following questions for a byte-addressed virtual memory system that uses the

following virtual and physical address formats.

Virtual Address

page number page offset total VA length

28 + 12 = 40

Physical Address

frame number page offset total PA length

20 + 12 = 32

Part A (10 points) Determine the following values:

page size 4 Kbytes

size of virtual address space (byte addressed) 1 Tbytes

size of physical memory (used for frames) 4 Gbytes

number of pages 256 M pages

number of frames 1 M frames

Part B (8 points) Assume the following translations are available in the page table (all values are

in hexadecimal). For each virtual address listed below, determine the corresponding physical

address (if available). Indicate which VAs will result in a page fault given this table.

page number frame number disk location

CAB1234 F6C3 2364514

DE826 111 2836452

35C D3A4B 7665358

DE829 N/A 2754830

DE820 325 3476268

virtual address physical address page fault?

DE8269AC 1119AC N

DE82012 N/A (unallocated) Y

DE829248 N/A (on disk) Y

35CF64 D3A4BF64 N

Part C (2 points) What virtual address would translate to the physical address F6C3358 using

the page table in part B?

Virtual Address: CAB

5 problems, 7 pages Final Exam Solutions 7 December 2004

Problem 2 (2 parts, 20 points) Associative Sets

Part A (8 points) Consider a hash table that uses seven buckets. Suppose our hash function is the sum of the character codes of the characters in the key modulo the number of buckets B=7. Assume the character codes are as follows (A=1, B=2, C=3, D=4, E=5, F=6, G=7, H=8, I=9, J=10, K=11, L=12, M=13, N=14, O=15, P=16, Q=17, R=18, S=19, T=20, U=21, V=22, W=23, X=24, Y=25, Z=26). That is, the hash function is:

h ( k ) CharacterCode ( k )mod B ,

i

=∑ i

where i = 0 … |key|-1 and ki is the i th^ character of the key.

Suppose the hash table is implemented using closed hashing with a quadratic probe strategy to handle collisions. That is, the elements of the hash table are stored within the bucket array itself, using h(k) to determine the bucket. However, if a collision occurs, compute a series of alternative locations in the bucket array until one with the same key or an empty one is found. The alternative locations h 1 (k), h 2 (k), etc. are computed using a secondary quadratic probe function:

h j ( k )=( h ( k )+ j^2 )mod B ,

where j = 1, 2, …, B-1. Show the result of inserting the following (key, value) pairs into this hashtable. (“GLOBE”, “Boston”) (“AJC”, “Georgia”), (“CT”, “Chicago”), (“WPOST”, “D.C.”), (“BCA”, “British Columbia”). Note that this sequence of pairs is different from the one used in Exam 3. 0 AJC Georgia 1 BCA British Columbia 2 CT Chicago 3 WPOST D.C. 4 5 6 GLOBE Boston

Part B Now consider a hash table that uses a chaining strategy (implemented with a singly linked list) to handle collisions. The hash table has seven buckets and inserted entries are pushed on the front of the bucket list. Suppose the hash table has an average key length of three characters and an average bucket list length of 11 , (i.e., each bucket has approximately 11 entries). For the following questions assume that computing the hash function takes an average of four operations and comparing two strings takes an average of six operations. Ignore effects of spatial and temporal reference locality.

Part B.1 (4 points) How many of these operations would be required for the average lookup in the hash table described above? (show work)

4 + 6 (11 + 1)/2 = 40 Operations

Part B.2 (4 points) If instead of a hash table, an unsorted list were used to store the same entries, how many operations would be required for the average lookup using sequential search? (show work)

# elements = 7*11=

6(77+1)/2 = 234 Operations

Part B.3 (4 points) If we wanted to store the same entries in a hashtable that uses closed hashing with a simple linear probe strategy, what is the minimum number of buckets we would need to hold all the entries? (show work)

# elements = 7*11=

77 Buckets

5 problems, 7 pages Final Exam Solutions 7 December 2004

Part D (5 points) Fill in the MIPS code after the call to Solve to restore the values from Solve’s activation frame and assign the value of “x”. lw $31, 20($29) # restore return addr lw $30, 16($29) # restore frame pointer lw $3, 0($29) # load in return value addi $29, $29, 24 # pop Solve’s activation frame sw $3, -4($30) # update the value of x in Test’s AF

Part E (4 points) Finish the implementation of Test by implementing its return to its caller. lw $3, -4($30) # $3: x (optional, already in $3) sw $3, 0($30) # store x in return value slot add $29, $30, $0 # pop off locals jr $31 # return to caller of Test

5 problems, 7 pages Final Exam Solutions 7 December 2004

Problem 4 (2 parts, 15 points) Programming

Part A (10 points) Consider the following C code. sum = 0; i = 0; elt = V[0]; do { sum += elt; i++; elt = V[i]; } while (elt != -9999); avg = sum/i;

Assume that registers $2 and $3 contain the values of variables sum and i, respectively. Complete the following MIPS code fragment with the appropriate instructions to implement the C code. Place the current elt in register $4 and the resulting avg in register $1. For maximum credit, use a minimum number of MIPS instructions. You may use additional registers.

.data

V: .word 33, 44, 55, …, -9999, 100, 3, 22

.text

Start: addi $2, $0, 0 # sum = 0;

addi $3, $0, 0 # i = 0;

addi $5, $0, -9999 # set sentinel value

lw $4, V($0) # elt = V[0]

Loop: add $2, $2, $4 # sum += elt;

add $3, $3, 1 # i++;

sll $6, $3, 2 # compute EA for V[i]

lw $4, V($6) # elt = V[i];

bne $4, $5, Loop

# loop if elt not

sentinel

div $2, $3 # sum/i

mflo $

Part B (5 points) Perform at least one standard compiler optimization on the following C code fragment by writing the optimized version (in C) to the right.

z = (x * y)+ v/(x * y); t = x * y;

m = 16 * x; Ö Z = t + v/t;

n = m + (x * y) m = x << 4;

n = m + t;

In 5 words or less, describe which standard compiler optimization you applied:

Common subexpression elimination (or if you do the left shift change: strength reduction)

5 problems, 7 pages Final Exam Solutions 7 December 2004

Part B: Control Flow Graph

B

B

B

B

B

B

B

B

B

B

B

T

T

T

F

F

F

T

F T

F

F T