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

Code Generation

The document discusses code generation which is used to produce target code for three-address statements. It uses registers to store operands and describes the register and address descriptors, code generation algorithm, and an example of generating code for an assignment statement.

Uploaded by

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

Code Generation

The document discusses code generation which is used to produce target code for three-address statements. It uses registers to store operands and describes the register and address descriptors, code generation algorithm, and an example of generating code for an assignment statement.

Uploaded by

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

12/10/22, 10:07 AM Code Generation - javatpoint

Home Compiler Data Structure C C++ C# Java SQL HTML CSS JavaScript

Celebrating Durga Puja With Jisshu Sengupta


Zee Zest
Sponsored

https://www.javatpoint.com/code-generation 1/7
12/10/22, 10:07 AM Code Generation - javatpoint

Code Generator
Code generator is used to produce the target code for three-address statements. It uses registers to
store the operands of the three address statement.

Example:

Consider the three address statement x:= y + z. It can have the following sequence of codes:

MOV x, R0
ADD y, R0

Register and Address Descriptors:

A register descriptor contains the track of what is currently in each register. The register
descriptors show that all the registers are initially empty.

An address descriptor is used to store the location where current value of the name can be
found at run time.

A code-generation algorithm:
The algorithm takes a sequence of three-address statements as input. For each three address
statement of the form a:= b op c perform the various actions. These are as follows:

1. Invoke a function getreg to find out the location L where the result of computation b op c
should be stored.

2. Consult the address description for y to determine y'. If the value of y currently in memory
and register both then prefer the register y' . If the value of y is not already in L then generate
the instruction MOV y' , L to place a copy of y in L.

3. Generate the instruction OP z' , L where z' is used to show the current location of z. if z is in
both then prefer a register to a memory location. Update the address descriptor of x to
indicate that x is in location L. If x is in L then update its descriptor and remove x from all
other descriptor.

4. If the current value of y or z have no next uses or not live on exit from the block or in register
then alter the register descriptor to indicate that after execution of x : = y op z those register
will no longer contain y or z.

https://www.javatpoint.com/code-generation 2/7
12/10/22, 10:07 AM Code Generation - javatpoint

Generating Code for Assignment Statements:

The assignment statement d:= (a-b) + (a-c) + (a-c) can be translated into the following sequence of
three address code:

t:= a-b
u:= a-c
v:= t +u
d:= v+u

Code sequence for the example is as follows:

Statement Code Generated Register descriptor Address descriptor


Register empty

t:= a - b MOV a, R0 R0 contains t t in R0


SUB b, R0

u:= a - c MOV a, R1 R0 contains t t in R0


SUB c, R1 R1 contains u u in R1

v:= t + u ADD R1, R0 R0 contains v u in R1


R1 contains u v in R1

d:= v + u ADD R1, R0 R0 contains d d in R0


MOV R0, d d in R0 and memory

https://www.javatpoint.com/code-generation 3/7
12/10/22, 10:07 AM Code Generation - javatpoint

← Prev Next →

The Compatibility
Test - Watch Full…
Zee Zest

For Videos Join Our Youtube Channel: Join Now

Feedback

Send your Feedback to [email protected]

Help Others, Please Share

Learn Latest Tutorials

Splunk tutorial SPSS tutorial


https://www.javatpoint.com/code-generation 4/7
12/10/22, 10:07 AM Code Generation - javatpoint

Splunk SPSS
Swagger T-SQL tutorial
tutorial
Transact-SQL
Swagger

Tumblr tutorial React tutorial Regex tutorial Reinforcement


learning tutorial
Tumblr ReactJS Regex
Reinforcement
Learning

R Programming RxJS tutorial React Native Python Design


tutorial tutorial Patterns
RxJS
R Programming React Native Python Design
Patterns

Python Pillow Python Turtle Keras tutorial


tutorial tutorial
Keras
Python Pillow Python Turtle

Preparation

Aptitude Logical Verbal Ability Interview


Reasoning Questions
Aptitude Verbal Ability
Reasoning Interview Questions

Company
Interview
Questions
Company Questions

Trending Technologies

Artificial AWS Tutorial Selenium Cloud


Intelligence tutorial Computing
AWS
Tutorial tutorial
Selenium

https://www.javatpoint.com/code-generation 5/7
12/10/22, 10:07 AM Code Generation - javatpoint

Artificial Cloud Computing


Intelligence

Hadoop tutorial ReactJS Data Science Angular 7


Tutorial Tutorial Tutorial
Hadoop
ReactJS Data Science Angular 7

Blockchain Git Tutorial Machine DevOps


Tutorial Learning Tutorial Tutorial
Git
Blockchain Machine Learning DevOps

Sponsored

10 Eye-Catching Ikat Looks For A


True Textile Lover
ZeeZest.Com

B.Tech / MCA

DBMS tutorial Data Structures DAA tutorial Operating


tutorial System tutorial
DBMS DAA
Data Structures Operating System

Computer Compiler Computer Discrete


Network tutorial Design tutorial Organization and Mathematics
Architecture Tutorial
Computer Network Compiler Design
Computer Discrete
Organization Mathematics

Ethical Hacking Computer Software html tutorial


Tutorial Graphics Tutorial Engineering
Web Technology
Tutorial
Ethical Hacking Computer Graphics
Software
Engineering

https://www.javatpoint.com/code-generation 6/7
12/10/22, 10:07 AM Code Generation - javatpoint

Cyber Security Automata Safari IndiaC-Language C++ tutorial


Welcome To The Wild - Watch First
tutorial Tutorial Episode tutorial
C++
Cyber Security Automata Zee Zest C Programming
Sponsored

Java tutorial .Net Python tutorial List of


Framework Programs
Java Python
tutorial
Programs
.Net

Control Data Mining Data


Systems tutorial Tutorial Warehouse
Tutorial
Control System Data Mining
Data Warehouse

https://www.javatpoint.com/code-generation 7/7

You might also like