{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw8soln

# hw8soln - mult r1 r2 => r1 loadAI [email protected] => r2 sub r1 r2...

This preview shows pages 1–3. Sign up to view the full content.

HW#8 Solution Problem 1 - Type Systems (1) &a RuleA1 E a : integer E &a : pointer(integer) (2) *a RuleA2 E a : pointer(integer) !!! does not hold E *a : integer (3) *&a We need to use an associative rule for determining which operator to apply first. Since we're using C syntax, we'll use C associative rules which say that above operators are right associative. RuleA1 E a : integer E &a : pointer(integer) RuleA2 E &a : pointer(integer) E *&a : integer (4) &&a RuleA1 E a : integer E &a : pointer(integer) RuleA1 E &a : integer !!! does not hold E &&a : pointer(integer)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Problem 2 Code Generation for Expressions We'll order the computation to use the minimum number of registers. w + ((x * y) - z) loadAI r0, @x => r1 loadAI r0, @y => r2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: mult r1, r2 => r1 loadAI r0, @z => r2 sub r1, r2 => r1 loadAI r0, @w => r2 add r1, r2 => r1 Only two registers for needed to perform the computation (without counting r0). 3. Three-Address Code (ILOC) loadI 0 => r1 storeAI r1 => r0, @i storeAI r1 => r0, @sum HEAD: nop loadAI r0, @i => r2 loadI 10 => r3 cmp_LT r2, r3 => r4 cbr r4, BODY, EXIT BODY: nop loadAI r0, @i => r5 multI r5, 4 => r6 addI r6, @a => r7 loadAO r0, r7 => r8 addI r8, 1 => r9 storeAO r9 => r0, r7 loadAI r0, @sum => r10 add r10, r7 => r11 storeAI r11 => r0, @sum addI r5, 1 => r12 storeAI r12 => r0, @i jump HEAD EXIT: nop loadAI r0, @sum => r13 loadI 0 => r14 store r13 => r14 output 0...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

hw8soln - mult r1 r2 => r1 loadAI [email protected] => r2 sub r1 r2...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online