0% found this document useful (0 votes)
4 views

Code Generation

Code generation is the process of creating assembly or machine language from high-level code, focusing on correctness, high quality, efficient resource use, and quick execution. It involves various phases such as instruction selection, register allocation, and error handling, ensuring that the generated code is unambiguous and optimized for the target machine. The document also discusses the importance of using registers effectively during code generation to enhance performance.

Uploaded by

poonam2247backup
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Code Generation

Code generation is the process of creating assembly or machine language from high-level code, focusing on correctness, high quality, efficient resource use, and quick execution. It involves various phases such as instruction selection, register allocation, and error handling, ensuring that the generated code is unambiguous and optimized for the target machine. The document also discusses the importance of using registers effectively during code generation to enhance performance.

Uploaded by

poonam2247backup
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CODE GENERATION

s e
T2
Oe
generahion is the im task or achivihy of the compiles. Code generation
PTocess of cveating. Assembly/Machine language . Folloeing are the properies O
the code-generatfon.
c). Efficient use of
resource of target machip
a). Correctness b). High uality
d. Qurck code Generatfon.

executed.It is
Useful
jo Sma
and nialu
Cede Fixed location fn memoru

0 r e Machine
program
be placed coheve-eved
elocctcable Machine Code' not a fized location, code can cemmercia
have
Compilex8.
RAM, Itis useful for
find the xoom n

8howa
be corect anal
its purpase
code Aenerated should
aCOectness:
Itmeans that the
be altex3.
tree ,ancd exroT ree
code ahoud be ambiauity
It means thot
b . High-ualit:
o h th
I t is the
code geneva ton phase
Regource of lavget Machine, whe ther e ffitwent
c) Effiui ent use of to check
So it takes res ponsibiliby
make use
of target machine, or not
mahine taking place
0se 6f
resource of target
then immedu'ekela
cess ends
compilalton pro
,

:
When the maahine
Code Creneration
.

d.Quick execuion o n
code for that for
generate
Interme.diate Code
Creneratin
Code Ophmizahon
Tntermediae Coele:
Aclehreu Code Error
4).Three
b) Post NMotatton Handler
Sumbo
e) Syntau Tree
Table
d uadruple
e).Tiple

Code Cenevation

Target code Assembly Code

Assemble
Mathine (o de

Absolute M/t tode


JO
M/e tode
Kelo tatrble
SSueS in Code Ctehesarto"

d. Tnput to cocde genevation


(2). Taxget program
(3). Memovy management
C4d 1shuction SelecHon
C5 Reg'stov Allocatfon.

Instuth n Se lec hon


code:
We haue 3 Add vess
= b+C
exqple J. example 2 d= a+e
Yt2 movb, Ro
Mov Y, Ro ADD C, Ro
Code tenerohan ADD Z, Ro moy Ro,a Repeot Redundan t
MoV Ro,X moy a, Ro
ADD e, Ro KItis not efft uent
Assembl tocde
mov Po,d

mev Ro
ADD C, Ro
Cfhtent Aserbly
ADD , Ro Cde
mov o, .

Register Al te cobion for the alven Instuth on, we haye utecd onl one Registex Ro

whenever we have to move a vaiable, or add variable ar we have to perfovm an operatiom

e make use of Reaister If we have more than one regisher usage, then how Tegi'stes

allocotiom totes place

Exaple', -
Ho Reg'stey Alocaion takes plate for he aiven three Addreu code,

T A+8 MOV A, Ro
T T*C- LA DD 8,Ro

T T/ D MUL C,Ro
DIv d, Ro
MoV RoT
then hoo Tesste
f the Input te the Code Generahon phase Is Syu tree
allecation todtes plate'
Cadcudoe miui mum Regis ke
Reqirtd

Vofi

Ro a
R b

( q -b Ro Ro- R
N o w R can be fee, to be ed kr
othes volue.

(2 Ctd

R R,+R2
New R can be free

Ro-) C3 Ce) +d)

tCRee
e

- R2-R
R free
et

( a-b)+ P2
Re
foc-) -(P)fae

Rot P2
Ro
e, free

et
tfee Here 3 Pegistex have ured

You might also like