Target Code Generation: Utkarsh Jaiswal 11CS30038
Target Code Generation: Utkarsh Jaiswal 11CS30038
Generation
UTKARSH JAISWAL
11CS30038
Intermediate
Code
Code Target
Generation Machine
Code
Module
Symbol
Table
Pre-requisites
Load/Store operations:
op dest, src
Eg. :
Load R0, X
Store X, R0
Arithmetic/ Logical operations:
op dest, src1, src2
Eg.:
ADD R0, R1, R2
ADD R0, R1, M
where M corresponds to a memory location.
Control operations:
Unconditional Branch:
brn L
Conditional branch:
BGTZ x L
Addressing Modes
Knowing when the value of a variable will be used next is essential for generating good code.
If there is a three-address instruction sequence of the form
i: x = y + z
.
. no assignments to x between instructions i and j
.
j: a = x + b
then we say statement j uses the value of x computed at i.
We also say that variable x is live at statement i.
A simple way to find next uses is to scan backward from the end of a basic block keeping track
for each name x whether x has a next use in the block and if not whether x is live on exit from
that block.
Code Generation Algorithm