100% found this document useful (1 vote)
1K views

Design Issues: 1. Input To The Code Generator

The document discusses several design issues that can arise during the code generation phase of compiling source code to machine code. These include: 1) Choosing an appropriate intermediate representation to pass from the front end to the code generator. 2) Deciding on the target format for the generated machine code, such as assembly language or machine code. 3) Managing memory allocation for variables, such as placing local variables on the stack and global variables in static memory areas.

Uploaded by

Aashutosh Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views

Design Issues: 1. Input To The Code Generator

The document discusses several design issues that can arise during the code generation phase of compiling source code to machine code. These include: 1) Choosing an appropriate intermediate representation to pass from the front end to the code generator. 2) Deciding on the target format for the generated machine code, such as assembly language or machine code. 3) Managing memory allocation for variables, such as placing local variables on the stack and global variables in static memory areas.

Uploaded by

Aashutosh Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Design Issues

In the code generation phase, various issues can arises:

1. Input to the code generator


2. Target program
3. Memory management
4. Instruction selection
5. Register allocation
6. Evaluation order

1. Input to the code generator


o The input to the code generator contains the intermediate representation of the source
program and the information of the symbol table. The source program is produced by the
front end.
o Intermediate representation has the several choices:
  a) Postfix notation
  b) Syntax tree
  c) Three address code
o We assume front end produces low-level intermediate representation i.e. values of names
in it can directly manipulated by the machine instructions.
o The code generation phase needs complete error-free intermediate code as an input
requires.

2. Target program:
The target program is the output of the code generator. The output can be:

a) Assembly language: It allows subprogram to be separately compiled.

b) Relocatable machine language: It makes the process of code generation easier.

c) Absolute machine language: It can be placed in a fixed location in memory and can be
executed immediately.

3. Memory management
o During code generation process the symbol table entries have to be mapped to actual p
addresses and levels have to be mapped to instruction address.
o Mapping name in the source program to address of data is co-operating done by the front
end and code generator.
o Local variables are stack allocation in the activation record while global variables are in
static area.

4. Instruction selection:
o Nature of instruction set of the target machine should be complete and uniform.
o When you consider the efficiency of target machine then the instruction speed and
machine idioms are important factors.
o The quality of the generated code can be determined by its speed and size.

Example:
The Three address code is:

1. a:= b + c  
2. d:= a + e  

Inefficient assembly code is:

1. MOV b, R0              R0→b                              
2. ADD c, R0   R0      c + R0  
3. MOV R0, a               a   →   R0  
4. MOV a, R0      R0→  a  
5. ADD e, R0               R0  →       e + R0  
6. MOV R0, d               d    →  R0  

5. Register allocation
Register can be accessed faster than memory. The instructions involving operands in register are
shorter and faster than those involving in memory operand.

The following sub problems arise when we use registers:

Register allocation: In register allocation, we select the set of variables that will reside in
register.

Register assignment: In Register assignment, we pick the register that contains variable.

Certain machine requires even-odd pairs of registers for some operands and result.

For example:
Consider the following division instruction of the form:

1. D x, y  

Where,

x is the dividend even register in even/odd register pair

y is the divisor

Even register is used to hold the reminder.

Old register is used to hold the quotient.


6. Evaluation order
The efficiency of the target code can be affected by the order in which the computations are
performed. Some computation orders need fewer registers to hold results of intermediate than
others.

You might also like