Lab – Instruction Selection
What does the code look like?
 for some simple programs
Examine Mips/Codegen.java
Select code for some given tree tiles
Find some other tiles?
Note – these slides are available on the web

Compile some simple programs
Delete Mips/Codegen.class so that you get the full compiler
Get the gist of the available instructions
Consult the SPIM manual if you are unsure what some of them are doing

Examine munchStm( Tree.MOVE s )
In Mips/Codegen.java, line 85
Notice how a number of possible MOVE tiles are tested for
Two tiles starting at line 175 don’t emit any code yet
Fill these in
What instruction do you need?  Look in SPIM manual?
How will you marshal the necessary operands?
Remember options of OPER, MOVE, LABEL – consult book if you’re unsure of the difference
Be sure to write a program that will make use of these two tiles – to test if you’ve got it right

Examine munchExp( Tree.CONST e )
In Mips/Codegen.java, near line 300
Again, what code do you need for a simple constant?

Examine munchExp( Tree.CALL s )
In Mips/Codegen.java, at the end
Read up on the calling convention…
What series of instructions do you require here?
What might munchArgs be doing?
Hints!
Pass the static link in the result register
What arguments are passed in registers – and which registers to use?
Read manual, and look at Mips/MipsFrame.java
Pass additional arguments on the stack – they go ABOVE the stack pointer of the current frame
Remember space is allocated for all arguments – even though the first four are passed in registers
How is the system recording the maximum number of arguments ever required in a fn call from this frame?

Extras….
Hints
Look for the most efficient code possible
Are there simple optimisations you can make?
Note there is a ZERO register.  Can you make use of it anywhere?

Last Competition!!!
Can you see more efficient code tiles?
This set is complete – but can you find some more efficient tiles?
Prize for best submission – for a tile that often appears in tree code, and for which you produce more succinct code…
Send me your Codegen.java, indicating where you’ve inserted the new tile(s)