Exercise 7        Name __________________        Score __/18

Give the IR for the following:

  1. (2) 3 * 5 - 4
     
    BINOP(
       BINOP.SUB,
       BINOP(
           BINOP.MUL,
           CONST(3),
           CONST(5)
       ),
       CONST(4)
    )    
  2. (3) a = 3, assume a is in frame at offset 5 and TEMP(fp) is the frame pointer value.
     
    MOVE(
        MEM(
           BINOP(
                BINOP.PLUS,
                TEMP(fp),
                CONST(5)
           )
         ),
         CONST(3)
    )
  3. (3) a = b, assume a and b are in frame at offset 5 and 7 respectively and TEMP(fp) is the frame pointer value.
     
    MOVE(
        MEM(               ;a
           BINOP(
                BINOP.PLUS,
                TEMP(fp),
                CONST(5)
           )
         ),
         MEM(              ;b
           BINOP(
                BINOP.PLUS,
                TEMP(fp),
                CONST(7)
           )
         ),
    )
  4. (4) 4 < 5
     
    ESEQ(
        SEQ(
            SEQ(
                SEQ(
                    MOVE(TEMP(t),CONST(0)),
                    CJUMP(Tree.CJUMP.LT, CONST(4), CONST(5), T, F)
                 ),
                 SEQ(
                     LABEL(T),
                     MOVE(TEMP(t),CONST(1))
                  )
            ),
            LABEL(F)
        ),
        TEMP(t)
    )
  5. (6) while ( a < b )
         a = b
ESEQ(
      SEQ(
            SEQ(
                  LABEL(test),
                  CJUMP(Tree.CJUMP.EQ,
                            condition
                            CONST(1),T,F)
            ),
            SEQ(
                  SEQ(
                      LABEL(T),
                      body
                   ),
                   Tree.JUMP( test )
             )
      ),
      LABEL(F)
)

condition from Question 4

body from Question 3