

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


For these questions, use a three-address intermediate representation like the one we used in class. The instructions are:
x = y x = n x = &y (get address of variable y) x = a op b, where a and b are names or constants, and op is any arithmetic, comparison, or boolean operator JUMP label CJUMP x, Lt, Lf (jump to Lt if x is true, Lf otherwise) x = LOADIND y (get value in location contained in y) ERROR (return an error)
You may use any of the following translation schemes, which were discussed in class, except if a question requires you to use a particular one:
[S] = instruction list to compute statement S [e] = pair containing instruction list to compute expression e and variable name giving location of result [S] (^) blab,clab = instruction list for S, in context of while or switch statement, where blab is the break label (label after the enclosing while or switch) and clab is the continue label (label to start next iteration of while). [e] (^) x = instruction list to calculate value of e and place it in x [e] (^) tlab,flab = instructions to calculate boolean-valued expression e and jump to tlab if it is true, flab otherwise. (This is called the “short-circuit evaluation” scheme.)
compiled code should halt with an error (i.e. execute the ERROR instruction) if i< lo or i>hi. As in class, you will need to use the x = &A and LOADIND instructions.