Power point slides for lecture 23

Download Report

Transcript Power point slides for lecture 23

• Issues in compiling PASC into SPARC
– Predefined subroutines.
• Write them in C
• Compile them with GCC or CC
• Code generation must following the CC calling
– %o0: first argument
– %o1: second argument
• See lib.c and t1.s
• Memory allocation:
– Global variables: just allocation a chunk of
• Augment the symbol table to include offsets.
• You can associate the symbol with its location.
• Still need to use offset to deal with arrays and
• Accessing the variables: see t2.pasc
– Local variables:
• Allocate space on the stack.
• Access the variable through the frame point (using
the offset information)
• Memory allocation:
– Temporaries:
• To simplify the compilation, we can always use
memory to store the temporaries.
• With the reuse scheme, the number of temporaries
would not be too many – can just allocate as a
global data
– Code generation for calculations
• SPARC only performs computations using registers.
• Can just generate a sequence of code for each
intermediate instruction, such as t1 := t2 + t3
• See example t3.s
• Other features of sparc assembly:
– Delay slot – the instruction after a branch
instruction will be executed.
– To simplify code generation, add ‘nop’ to every
branch instruction.
– save/restore: the use of register files to speed up
function calls.
– Data alignment: integers must be aligned to 4
• The use of proj4.c
– See example1.c and example2.c
– It would help if you implement the generate
emit routine.