Docsity

Solved Problems on Mechanisms-Computing System - Old Exam 2 | ECE 3035, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035 A & B Computing Mechanisms Spring 2005
4 problems, 4 pages Exam Two Solution 6 March 2005
1
Problem 1 (4 parts, 28 points) PathFinder Implementation
Consider the following fragment from the PathFinder baseline implementation:
Loop2: addi $3, $3, -32 # I01
lw $4, Array($3) # I02
addi $5, $3, 4 # I03
lw $5, Array($5) # I04
slt $6, $5, $4 # I05
beq $6, $0, Skip1 # I06
add $4, $5, $0 # I07
Skip1: addi $3, $3, 8 # I08
lw $5, Array($3) # I09
add $5, $5, $4 # I10
sw $5, Array($3) # I11
addi $3, $3, 36 # I12
lw $5, Array($3) # I13
add $5, $5, $4 # I14
sw $5, Array($3) # I15
addi $3, $3, -44 # I16
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 # I05
bne $6, $0, Skip1 # I06
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.
pf3
pf4

Partial preview of the text

Download Solved Problems on Mechanisms-Computing System - Old Exam 2 | ECE 3035 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

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.

  1. Mark and sweep GC has highly non-uniform allocation cost (non-incremental)
  2. Mark and sweep GC does not yield contiguous free space (non-compacting)

Part B (4 points) List two benefits of dynamic (weak) typing.

  1. Dynamic typing does not require type declarations in source code.
  2. Dynamic typing support automatic garbage collection.

Part C (6 points) List three differences between the heap and static data storage.

  1. Heap data is dynamically allocated; static data is statically allocated.
  2. Heap data is explicitly managed by application program; static data is unmanaged.
  3. Heap data can be reused through program; static data is permanent.

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