






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!







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:
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).
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.
Part B.3 (4 points) Draw the interference graph using the nodes to represent the webs identified in part B.2.
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
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
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 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
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.
Part D (3 points) Which objects would be reclaimed by a reference count garbage collection scheme?
List their starting addresses:
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
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*