Exercise 9        Name __________________        Score __/18

  1. (9) For each of the following expressions, draw the tree and generate Jouette-machine instructions using maximal munch. Circle the tiles (as in Figure 9.2) but number them in the order they are munched and show sequence of Jouette instructions that result.

     

    1. MOVE(MEM(TEMP x), MEM(+ (TEMP fp, CONST 1)))
    2. MOVE(MEM( + ( + (CONST 1000, MEM(TEMP x)), TEMP fp)), CONST 0)

       

  2. (9) The Jouette machine has control-flow instructions as follows:
    1. BRANCHGE    if ri >= 0 goto LABEL
    2. BRANCHLT     if ri < 0 goto LABEL
    3. BRANCHEQ    if ri == 0 goto LABEL
    4. BRANCHNE    if ri != 0 goto LABEL
    5. JUMP            goto ri

    where the JUMP instruction goes to an address contained in a register.

    Use these instructions to implement the following tree patterns:

        JUMP            JUMP                      CJUMP  
           |                  |                       /  |  |   |  \ 
                            NAME                EQ        T   F

    Assume that a CJUMP is always followed by its false label and the T and F label basic blocks. Show the best way to implement each pattern; in some cases you may need to use more than one instruction or make up a new temporary.