Docsity

Final Exam with 5 Problems - Mechanisms Computing System | ECE 3035, Exams of Electrical and Electronics Engineering

Partial preview of the text

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

5 problems, 11 pages Final Exam 2 May 2005

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have

a question, raise your hand and I will come to you. Please work the exam in pencil. For

maximum credit, show your work.

Good Luck!

Your Name ( please print ) ________________________________________________

1 2 3 4 5 total

5 problems, 11 pages Final Exam 2 May 2005

Problem 1 (2 parts, 14 points) Syntactic and Semantic Analysis

Part A Consider the following attribute grammar GA.

Productions Semantic Rules S (^) ร† E S.result = E.result E (^) L ร† E (^) R op int E (^) L.result = E (^) R.result op.val int.val E (^) L ร† lpar^ E^ R rpar^ E^ L.result^ =^ E^ R.result E (^) ร† int E.result = int.val

Lexical analysis breaks up text strings into tokens according to the following specification, with the โ€œvalโ€ attribute of each token equal to the number or operator in the token: op (^) = + | - | * | / int (^) = [0-9]+ lpar (^) = ( rpar (^) = )

So the string โ€œ6+9โ€ is scanned into the sequence of tokens: <int, val: 6>, <op, val: +>, <int, val: 9>.

Part A.1 (3 points) Give a 5 token string that can be parsed with this grammar and show its parse tree.

Part A.2 (5 points) Draw the parse tree for the string โ€œ3 + 5 * 4 / 2โ€ and determine the S.result computed in recognizing this string.

S.result:?

Parse tree:

5 problems, 11 pages Final Exam 2 May 2005

Problem 2 (2 parts, 24 points) Register Allocation

Part A (4 points) What is the minimum number of colors needed to color this interference graph? Show the coloring. To color a node, write โ€œR,โ€ โ€œGโ€, โ€œBโ€, etc., in its circle. Show your work (e.g., show the color stack).

s

s

s

s

s

s

Colors

Part B Consider the following program fragment.

x = 5 + 3; if (p(x)) { y = 6; c = x + 7; z = f(c); h(y); } else { w = 6; z = x * 4; c = f(w); } a = c โ€“ 10; b = z * 2; g(a, b);

Part B.1 (4 points) The control flow graph for this fragment is shown on the next page. Fill in the definitions and uses of the variables (e.g., โ€œdef xโ€ and โ€œuse wโ€) in the basic blocks of the graph.

Part B.2 (5 points) Identify the webs (of def-use chains) in the control flow graph by drawing a region for each variable and labeling each web S 1 , S 2 , etc.

5 problems, 11 pages Final Exam 2 May 2005

T F

Part B.3 (4 points) Draw the interference graph using the nodes to represent the webs identified in part B.2.

5 problems, 11 pages Final Exam 2 May 2005

Problem 3 (2 parts, 20 points) Pointers and Arrays

The following declaration is allocated in static memory starting at memory location 5000.

int A = 64; int B = 16; int *C = &A; int D[5] = {90, 81, 72, 63, 54}; int E[16][8][32];

Part A (10 points) What will be the values of the listed variables following execution of this code fragment. Assume the code immediately follows the variable declarations.

*C = *C + A; C++; *C = *C + B

A B C

D D[2] &(D[2])

Part B (10 points) Write MIPS code that implements the following C statement in the smallest number of instructions. Assume I is found in $3, J is found in $4, and K is found in $5. Modify only $1 and $2.

E[I][J][K] = 512; Label Instruction Comment

5 problems, 11 pages Final Exam 2 May 2005

Problem 4 (4 parts, 25 points) Heap Manager Implementation

Consider the following fragment from the HeapManager baseline implementation. Recall that $

is the next free object pointer, $3 is the free list, and $4 is the required object size.

lw $6, -4($2) # I slt $5, $6, $4 # I bne $5, $0, Label1 # I lw $6, 0($2) # I add $3, $6, $0 # I beq $0, $0, Label3 # I Label1: add $7, $2, $0 # I lw $2, 0($2) # I beq $2, $0, Label2 # I lw $6, -4($2) # I slt $5, $6, $4 # I bne $5, $0, Label1 # I lw $6, 0($2) # I sw $6, 0($7) # I beq $0, $0, Label3 # I

Part A (6 points) Describe the conditions when I04 - I06 execute and what they accomplish

in terms defined in the project specification (e.g., object allocation, requested size, free list)

rather than a transliteration of MIPS instructions.

Part B (6 points) I10โ€“I15 are nearly identical to I01โ€“I06. Explain the difference in terms

defined in the project specification. Be specific.

Part C (4 points) When a null pointer is encountered in the free list, what label is branched to?

Part D (9 points) Suppose the free list contains five objects; but all are smaller than the

requested size. How many total instructions are executed in the fragment (i.e., from when the

fragment is entered to when it is exited)?

instructions

5 problems, 11 pages Final Exam 2 May 2005

Part B (3 points) Mark all objects reachable from the root set {Root} by placing a 1 in the Mark row.

Address $6000 $6016 $6032 $6048 $6064 $6080 $6096 $6112 $6128 $ Size 12 12 12 12 12 12 12 12 12 12 Value 7 2 3 8 6 1 5 4 45 14 Left $6096 $6144 $6032 $6016 $6112 $6112 $6144 $6080 $6144 Null Right $6016 $6080 $6064 $6064 Null Null $6128 Null Null Null

Mark:

Part C (3 points) Sweep up the unmarked objects and place them on the free list, by scanning from low address to high. Show the contents of the heap, including the free list at the end of this step. Suppose static memory address 3000 holds a pointer to the head of the free list. Fill in the contents of memory address 3000 below.

Address $6000 $6016 $6032 $6048 $6064 $6080 $6096 $6112 $6128 $

Size

Value

Left

Right

Part D (3 points) Which objects would be reclaimed by a reference count garbage collection scheme?

List their starting addresses:

Part E (3 points) List three differences between the heap and the stack.

Part F (2 points) Give an example of each of these:

1. asynchronous exception:

2. synchronous exception:

5 problems, 11 pages Final Exam 2 May 2005

MIPS Instruction Set (core)

Instruction Example Meaning Arithmetic add add $1,$2,$3 $1 = $2 + $ subtract sub $1,$2,$3 $1 = $2 - $ add immediate addi $1,$2,100 $1 = $2 + 100 add unsigned addu $1,$2,$3 $1 = $2 + $3, overflow undetected subtract unsigned subu $1,$2,$3 $1 = $2 - $3, overflow undetected add immediate unsigned addiu $1,$2,100 $1 = $2 + 100, overflow undetected set if less than slt $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if less than immediate slti $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 set if less than unsigned sltu $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if < immediate unsigned sltui $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 multiply mult $2,$3 Hi, Lo = $2 * $3, 64-bit signed product multiply unsigned multu $2,$3 Hi, Lo = $2 * $3, 64-bit unsigned product divide div $2,$3 Lo = $2 / $3, Hi = $2 mod $ divide unsigned divu $2,$3 Lo = $2 / $3, Hi = $2 mod $3, unsigned Transfer move from Hi mfhi $1 $1 = Hi move from Lo mflo $1 $1 = Lo

load upper immediate lui $1,100 $1 = 100 x 2 16

Logic and and $1,$2,$3 $1 = $2 & $ or or $1,$2,$3 $1 = $2 | $ and immediate andi $1,$2,100 $1 = $2 & 100 or immediate ori $1,$2,100 $1 = $2 | 100 nor nor $1,$2,$3 $1 = not($2 | $3) xor xor $1, $2, $3 (^) $1 = $2 โŠ• $ xor immediate xori $1, $2, 255 (^) $1 = $2 โŠ• 255 Shift shift left logical sll $1,$2,5 $1 = $2 << 5 (logical) shift left logical variable sllv $1,$2,$3 $1 = $2 << $3 (logical), variable shift amt shift right logical srl $1,$2,5 $1 = $2 >> 5 (logical) shift right logical variable srlv $1,$2,$3 $1 = $2 >> $3 (logical), variable shift amt shift right arithmetic sra $1,$2,5 $1 = $2 >> 5 (arithmetic) shift right arithmetic variable srav $1,$2,$3 $1 = $2 >> $3 (arithmetic), variable shift amt Memory load word lw $1, ($2) $1 = memory [$2] store word sw $1, ($2) memory [$2] = $ Branch branch if equal beq $1,$2,100 if ($1 = $2), PC = PC + 4 + (1004) branch if not equal bne $1,$2,100 (^) if ($1 โ‰  $2), PC = PC + 4 + (1004) Jump jump j 10000 PC = 10000* jump register jr $31 PC = $ jump and link jal 10000 $31 = PC + 4; PC = 10000*