Unit 4 Code Generation
Unit 4 Code Generation
(o1)
ADD (out= 2
Mimony lecato
Moy C
mevo
ADD RS to Rs and aodd
dusciptoos
Co ntent
deunp toack
hames
track d docation
* keup name Can be
walue
be
addes those
Raisken daoaiptan n
kuup tatt srod
A
code-generation algorithm
The algorithm takes as input a sequence of three-address statements constituting a basic block. For each
three-address statement of the formx:=y opz, perform the following actions:
1. Invoke a function getreg to determine the location L where the result of the computation y op z
should be stored.
2. Consult the address descriptor for y to determine y', the current kocation of y. Prefer the register for
' if the value of y is currently both in memory and a register. If the value of y is not already in L,
generate the instruction MOV y',Lto place a copy of yin L.
3. Generate the instruction OP 2', L where z' is a current location of z. Prefer a register to a memory
4. If the current values of y or z have no next uses, are not live on exit from the block, and are in
registers, alter the register descriptor to indicate that, after execution of x :=y op z, those registers will
no longer contain y or z
" The assignment d : (a-b) + (a-c) + (a-c) might be translated into the following three-address code
sequence:
CJ<z