


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



4 problems, 4 pages Exam Two Solution 6 March 2005
Problem 1 (4 parts, 28 points) PathFinder Implementation
Consider the following fragment from the PathFinder baseline implementation: Loop2: addi $3, $3, -32 # I lw $4, Array($3) # I addi $5, $3, 4 # I lw $5, Array($5) # I slt $6, $5, $4 # I beq $6, $0, Skip1 # I add $4, $5, $0 # I Skip1: addi $3, $3, 8 # I lw $5, Array($3) # I add $5, $5, $4 # I sw $5, Array($3) # I addi $3, $3, 36 # I lw $5, Array($3) # I add $5, $5, $4 # I sw $5, Array($3) # I addi $3, $3, -44 # I Part A (7 points) Using terms defined in the project specification (weights, path costs, etc.), what is contained in $4 when I08 begins execution? Be specific.
When I08 begins, $4 contains the cost of the shortest path from the starting
node to the current position.
Part B (7 points) Using terms defined in the project specification (weights, path costs, etc.), what is accomplished in I09 โ I15? Be specific.
Instructions I09-I15 add the minimum cost to the weights on the outgoing edges
from the current position.
Part C (7 points) What is the net change (in words) on the base pointer $03 following execution of this code fragment?
(-32 + 8 + 36 + -44) / 4 = -32 / 4 = -8 words
Part D (7 points) Would there be a performance penalty if I05 and I06 were changed to the following? Explain why or why not. slt $6, $4, $5 # I bne $6, $0, Skip1 # I
The original sequence updates $4 with the minimum cost if $5 is less than $4.
The new sequence updates $4 if $5 is less than or equal to $4. This will result
In an unnecessary update (and cost) when $5 and $5 are equal.
4 problems, 4 pages Exam Two Solution 6 March 2005
Problem 2 (4 parts, 28 points) DarkMaze Implementation
Part A (15 points) The following fragment is from the DarkMaze baseline. Recall that swi 505 is the probe operation and $7 is used to store the constant 2. Direction register $2 defines North = 0 , East = 1 , South = 2 , and West = 3. Result register $3 defines 0 = blocked, 1 = moved, and 2 = outside. swi 505 # I beq $3, $0, Skip1 # I beq $3, $7, Success # I jal Search # I Skip1: addi $2, $2, -1 # I andi $2, $2, 3 # I swi 505 # I beq $3, $0, Skip2 # I beq $3, $7, Success # I jal Search # I Skip2: addi $2, $2, 2 # I andi $2, $2, 3 # I swi 505 # I beq $3, $0, Skip3 # I beq $3, $7, Success # I jal Search # I Skip3: addi $2, $2, -1 # I Skip4: addi $2, $2, 2 # I andi $2, $2, 3 # I swi 505 # I addi $2, $2, 2 # I andi $2, $2, 3 # I Part A (7 points) Describe the direction of each probe operation, relative to the initial direction when the fragment begins?
I01: forward
I07: left
I13: right
I20: backward
Part B (7 points) What is the net change on the direction pointer $02 following execution of this code fragment?
Following execution of the fragment, the direction pointer is unchanged.
Part C (7 points) What happens, in terms of the higher level algorithm, when this fragment is entered at Skip4?
When entering at Skip4, the fragment backtracks out of the current cell.
Part D (7 points) Suppose in a given 16 x 16 maze, half the probes are blocked by walls, all cells are reachable, and the visit array limits duplicate exploration. Approximately how many wall probes are executed in the worst case maze search? In the worst case, every cell is fully explored. In each cell, there will be four outward probes. Ignoring revisits of cells (for which no data was provided), there will be approximately 16 x 16 x 4 = 1000 probes.
4 problems, 4 pages Exam Two Solution 6 March 2005
Problem 4 (4 parts, 24 points) Short Answer
Part A (4 points) List two limitations of mark and sweep garbage collection.
Part B (4 points) List two benefits of dynamic (weak) typing.
Part C (6 points) List three differences between the heap and static data storage.
Part D (10 points) Suppose the following object is allocated on the heap using malloc(). Assume the heap pointer is 5000 and there is no free list. Show where A, B, C, and D are placed in memory. Record the object size (i.e., write the actual size value where it belongs) and show the heap pointer following the allocation.
struct Thing { int A; int *B; char C[10]; double D; }
HP (^5000) size size size size = 28
(^5004) A A A A
(^5008) B B B B
(^5012) C[0] C[1] C[2] C[3]
(^5016) C[4] C[5] C[6] C[7]
(^5020) C[8] C[9] slack slack
(^5024) D D D D
(^5028) D D D D
HP 5032