Docsity

Exam II with Solution - Mechanisms Computing System | ECE 3035, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 3035 A Computing Mechanisms Fall 2005
4 problems, 7 pages Exam Two Solutions 21 November 2005
1
Problem 1 (4 parts, 30 points) HopMaze Implementation
The following fragments are from the HopMaze baseline. For your responses, describe their
behaviors using proper data structure nomenclature. Do not simply transliterate the MIPS
instructions.
Store: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Visit: .word -1, -1, -1, -1, -1, -1, -1, -1
...
addi $9, $0, Store # I01
addi $10, $0, Store # I02
...
lbu $1, 0($10) # I03
addi $10, $10, 1 # I04
slti $2, $10, Visit # I05
bne $2, $0, L1 # I06
addi $10, $0, Store # I07
L1: ...
...
sb $6, 0($9) # I08
addi $9, $9, 1 # I09
slti $2, $9, Visit # I10
bne $2, $0, L2 # I11
addi $9, $0, Store # I12
L2: ...
Part A (7 points) Describe the function of fragment I03-I07. Identify inputs and outputs.
These statements dequeue an element from the FIFO Queue “Store”
by loading the element pointed to by the tail ($10) into register
$1 and then updating the tail pointer (in: $10, out: $1, $10).
Part B (7 points) Describe the function of fragment I08-I12. Identify inputs and outputs.
These statements enqueue an element onto the FIFO Queue “Store”
by storing the element ($6) at the location pointed to by the
head ($9) and then updating the head (in: $6, $9, out: $9).
Part C (7 points) Explain why the last three instructions of these two fragments are needed.
They allow the pointers to wrap around when they get to the end
of the space allocated for Store; circular queue implementation.
Part D (9 points) In the HopMaze baseline, the positions of visited cells are maintained using
these fragments. Explain how this is useful in determining the shortest path to the exit.
This maintains the visited cells in a FIFO queue so that they are
explored in breadth-first order which guarantees a shortest path.
pf3
pf4
pf5

Partial preview of the text

Download Exam II with Solution - Mechanisms Computing System | ECE 3035 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

4 problems, 7 pages Exam Two Solutions 21 November 2005

Problem 1 (4 parts, 30 points) HopMaze Implementation

The following fragments are from the HopMaze baseline. For your responses, describe their behaviors using proper data structure nomenclature. Do not simply transliterate the MIPS instructions.

Store: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 Visit: .word -1, -1, -1, -1, -1, -1, -1, - ... addi $9, $0, Store # I addi $10, $0, Store # I ... lbu $1, 0($10) # I addi $10, $10, 1 # I slti $2, $10, Visit # I bne $2, $0, L1 # I addi $10, $0, Store # I L1: ... ... sb $6, 0($9) # I addi $9, $9, 1 # I slti $2, $9, Visit # I bne $2, $0, L2 # I addi $9, $0, Store # I L2: ... Part A (7 points) Describe the function of fragment I03-I07. Identify inputs and outputs.

These statements dequeue an element from the FIFO Queue “Store”

by loading the element pointed to by the tail ($10) into register

$1 and then updating the tail pointer (in: $10, out: $1, $10).

Part B (7 points) Describe the function of fragment I08-I12. Identify inputs and outputs.

These statements enqueue an element onto the FIFO Queue “Store”

by storing the element ($6) at the location pointed to by the

head ($9) and then updating the head (in: $6, $9, out: $9).

Part C (7 points) Explain why the last three instructions of these two fragments are needed.

They allow the pointers to wrap around when they get to the end

of the space allocated for Store; circular queue implementation.

Part D (9 points) In the HopMaze baseline, the positions of visited cells are maintained using these fragments. Explain how this is useful in determining the shortest path to the exit.

This maintains the visited cells in a FIFO queue so that they are

explored in breadth-first order which guarantees a shortest path.

4 problems, 7 pages Exam Two Solutions 21 November 2005

Problem 2 (3 parts, 30 points) Activation Frames

Consider the following C fragment: int foo(int R) { int m = 45; int n = 67; int p[4] = {9, 16, 25, 36}; m = bar(m, &n, p) + R + m; return m; } int bar(int A, *B, C[]) { int x, *y; y = B; x = C[2] + 5; *y = *y + 3; C[1] = C[1] + 4; return x; } Part A (10 points) Shown below is the current state of the stack when foo is called (i.e., just after the “jal foo” instruction in foo’s caller is executed). Fill in the unshaded boxes to show bar’s activation frame immediately before bar executes its “return x;” instruction. Include both a symbolic description and the actual value (in decimal). Do not include values for return addresses. Label the frame pointer and stack pointer. address description value 9900 RA of foo’s caller 9896 FP of foo’s caller 9892 R 25 SP, Foo’s FP 9888 return value (^9884) m 45

(^9880) n 67 70

(^9876) p[3] 36

(^9872) p[2] 25

(^9868) p[1] 16 20

(^9864) p[0] 9

(^9860) RA of foo

(^9856) FP of foo 9888

(^9852) A 45

(^9848) *B 9880

(^9844) *C 9876

FP 9840 (^) Bar’s return value

(^9836) x 30

SP 9832 (^) *y 9880

4 problems, 7 pages Exam Two Solutions 21 November 2005

Problem 3 (2 parts, 20 points) Storage Management

The following box and pointer diagram illustrates the object structure in the heap with external roots from the register file and stack as shown. Each box is annotated with the address of the object it represents. The sizes of the objects are not shown in the drawing.

null

null

null

null

6256: 7 6320 6224

6320: 85 null 6256

Registers: $0: 0 $1: 4 $2: 6 $3: 6012 $4: ...

Stack:

bar’s A.F.

Part A (12 points) List the address of all objects that will be reclaimed by each of the following garbage collection strategies. Strategy Addresses of Objects Reclaimed Reference Counting (^) 6144, 6080, 6032, 6112

Mark and Sweep 6144, 6080, 6032, 6112, 6000, 6128, 6048

Old-New Space (copying) 6144, 6080, 6032, 6112, 6000, 6128, 6048

Part B (8 points) Now suppose that the function bar returns and its activation frame is popped from the stack. Which additional objects will be reclaimed by each of the strategies? If none, write “none.” Strategy Addresses of Additional Objects Reclaimed Reference Counting None

Mark and Sweep 6320, 6256, 6224

Old-New Space (copying) 6320, 6256, 6224

4 problems, 7 pages Exam Two Solutions 21 November 2005

Problem 4 (3 parts, 20 points) Miscellany

Part A (6 points) Consider the following program fragment. Line number Instruction 10: int x; 11: float y = 3.14; 12: x = 5; 13: y = y + x; 14: x = “abc”; 15: x = x+y;

If the programming language is statically typed (such as C), at which line of code would a type error first occur? Assume the language has C-like coercion rules. Line number: 14.

If the programming language is dynamically typed , at which line of code would a type error first occur? Assume the language has C-like coercion rules. Line number: 15.

Part B (4 points) Compare static versus dynamic typing in terms of:

  1. runtime performance: static typing is faster at runtime (less runtime overhead)
  2. compilation time: dynamic typing has shorter compile time (no type checking)

Part C (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[2]; char B[7]; char *C; double D; } HP 5000 size size size size: 28

5004 A[0] A[0] A[0] A[0]

5008 A[1] A[1] A[1] A[1]

5012 B[0] B[1] B[2] B[3]

5016 B[4] B[5] B[6] slack

5020 ***C *C C C

5024 D D D D

(^5028) D D D D

HP 5032