Tutorial Week 8 |
Introduction. The purpose of this week's lab is to get more familiar with assembly programming. Task 1. For all
the programs below, given in pseudo-code, produce an
assembler program (using the stack-machine
see
here) that implements the same functionality. In
each case, we assume that various variables
(named Example. We want
to compute PushAbs "a" // Push the content of Programs. Here are the programs that you should translate into assembly.
Note. The
'commands' Task 2. Finish the
code generator for the accumulator machine (see
slides
here). Again this means thinking
about Task 3. Finish the
code generator for register machines with unlimited
registers (see
slides
here). This means thinking
about Task 4. In the lectures we devised a way of compiling for register machines with a fixed number of registers (where each register can function as an accumulator). We learned how to generate code for register machines with a fixed number of registers using a hybrid strategy:
(Modern industrial strength compilers use more sophisticated strategies that we may look at later.) In the lectures I gave you only the key clauses of the code generator that uses this hybrid strategy. I also only sketched the machine code of CPUs with a fixed number of registers, where registers can be used as accumulators. The reason for this brevity was that both are very similar to what you've seen previously (reproduced below). Your task is to supply the missing bits:
You can find the pseudo code for ASTs in the source language I used here if you want to use it. The parts of the code generator I gave you in the lectures that you need to complete is here. Something to think about: it is possible for a register machine to simulate an accumulator machine without adding commands. How? |