hw8soln

# hw8soln - mult r1, r2 =&amp;amp;gt; r1 loadAI r0, @z...

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

HW#8 Solution Problem 1 - Type Systems (1) RuleA1 E a : integer E : pointer(integer) (2) *a RuleA2 E a : pointer(integer) !!! does not hold E *a : integer (3) We need to use an associative rule for determining which operator to apply ﬁrst. 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 : pointer(integer) RuleA2 E : pointer(integer) E : integer (4) RuleA1 E a : integer E : pointer(integer) RuleA1 E : integer !!! does not hold E : 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 =&gt; r1 loadAI r0, @z =&gt; r2 sub r1, r2 =&gt; r1 loadAI r0, @w =&gt; r2 add r1, r2 =&gt; r1 Only two registers for needed to perform the computation (without counting r0). 3. Three-Address Code (ILOC) loadI 0 =&gt; r1 storeAI r1 =&gt; r0, @i storeAI r1 =&gt; r0, @sum HEAD: nop loadAI r0, @i =&gt; r2 loadI 10 =&gt; r3 cmp_LT r2, r3 =&gt; r4 cbr r4, BODY, EXIT BODY: nop loadAI r0, @i =&gt; r5 multI r5, 4 =&gt; r6 addI r6, @a =&gt; r7 loadAO r0, r7 =&gt; r8 addI r8, 1 =&gt; r9 storeAO r9 =&gt; r0, r7 loadAI r0, @sum =&gt; r10 add r10, r7 =&gt; r11 storeAI r11 =&gt; r0, @sum addI r5, 1 =&gt; r12 storeAI r12 =&gt; r0, @i jump HEAD EXIT: nop loadAI r0, @sum =&gt; r13 loadI 0 =&gt; r14 store r13 =&gt; r14 output 0...
View Full Document

## This note was uploaded on 10/29/2010 for the course CS 198:415 taught by Professor Kremer,u. during the Spring '10 term at Rutgers.

### Page1 / 3

hw8soln - mult r1, r2 =&amp;amp;gt; r1 loadAI r0, @z...

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

View Full Document
Ask a homework question - tutors are online