hw8soln - mult r1, r2 => r1 loadAI r0, @z...

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

View Full Document Right Arrow Icon
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 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 : 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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Background image of page 3
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

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 => r1 loadAI r0, @z...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online