0% found this document useful (0 votes)
19 views24 pages

CD Unit 5

aktu compiler design unit 5
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
0% found this document useful (0 votes)
19 views24 pages

CD Unit 5

aktu compiler design unit 5
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/ 24

Subject: Compiler Design Prachi Jain

Subject Code: KCS 502 Assistant Professor (CSE Dept.)

UNIT 5
CODE OPTIMIZATION & CODE
GENERATION
I. CODE OPTIMIZATION
o The process of code optimization involves-
 Eliminating the unwanted code lines
 Rearranging the statements of the code
o Optimization is a program transformation technique, which tries to improve the code
by making it consume less resources (i.e. CPU, Memory) and deliver high speed.
o In optimization, high-level general programming constructs are replaced by very
efficient low-level programming codes. A code optimizing process must follow the
three rules given below:
 The output code must not, in any way, change the meaning of the program.
 Optimization should increase the speed of the program and if possible, the program
should demand less number of resources.
 Optimization should itself be fast and should not delay the overall compiling process.
o Efforts for an optimized code can be made at various levels of compiling the process.
 At the beginning, users can change/rearrange the code or use better algorithms to
write the code.
 After generating intermediate code, the compiler can modify the intermediate code
by address calculations and improving loops.
 While producing the target machine code, the compiler can make use of memory
hierarchy and CPU registers.
o Advantages-
The optimized code has the following advantages-
 Optimized code has faster execution speed.
 Optimized code utilizes the memory efficiently.
 Optimized code gives better performance.
o Optimization can be categorized broadly into two types: machine independent and
machine dependent.

1. Machine-Independent Optimization
o Machine independent optimization attempts to improve the intermediate code to get a
better target code. The part of the code which is transformed here does not involve any
absolute memory location or any CPU registers.
o The process of intermediate code generation introduces much inefficiency like: using
variable instead of constants, extra copies of variable, repeated evaluation of
expression. Through the code optimization, you can remove such efficiencies and
improves code.
o It can change the structure of program sometimes of beyond recognition like: unrolls
loops, inline functions, eliminates some variables that are programmer defined.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

o Code Optimization can perform in the following different ways:


i. Compile Time Evaluation:
Two techniques that falls under compile time evaluation are-
(a) Constant Folding-
In this technique,
As the name suggests, it involves folding the constants.
The expressions that contain the operands having constant values at
compile time are evaluated.
Those expressions are then replaced with their respective results.
Example:
Circumference of Circle = (22/7) x Diameter
Here,
 This technique evaluates the expression 22/7 at compile time.
 The expression is then replaced with its result 3.14.
 This saves the time at run time.
(b) Constant Propagation-
In this technique,
If some variable has been assigned some constant value, then it
replaces that variable with its constant value in the further program
during compilation.
The condition is that the value of variable must not get alter in
between.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

Example:
pi = 3.14
radius = 10
Area of circle = pi x radius x radius
Here,
 This technique substitutes the value of variables ‘pi’ and ‘radius’ at
compile time.
 It then evaluates the expression 3.14 x 10 x 10.
 The expression is then replaced with its result 314.
 This saves the time at run time.
ii. Common Sub-Expression Elimination:
The expression that has been already computed before and appears again in the
code for computation is called as Common Sub-Expression.
In this technique,
As the name suggests, it involves eliminating the common sub
expressions.
The redundant expressions are eliminated to avoid their re-computation.
The already computed result is used in the further program when
required.
Example:

Code Before Optimization Code After Optimization

S1 = 4 x i
S1 = 4 x i
S2 = a[S1] S2 = a[S1]
S3 = 4 x j S3 = 4 x j
S4 = 4 x i // Redundant Expression S5 = n
S5 = n S6 = b[S1] + S5
S6 = b[S4] + S5

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

iii. Code Movement:


In this technique,
As the name suggests, it involves movement of the code.
The code present inside the loop is moved out if it does not matter
whether it is present inside or outside.
Such a code unnecessarily gets execute again and again with each
iteration of the loop.
This leads to the wastage of time at run time.
Example:

Code Before Optimization Code After Optimization

for ( int j = 0 ; j < n ; j ++) x=y+z;


{ for ( int j = 0 ; j < n ; j ++)

x=y+z; {

a[j] = 6 x j; a[j] = 6 x j;

} }

iv. Dead code elimination:


In this technique,
As the name suggests, it involves eliminating the dead code.
The statements of the code which either never executes or are
unreachable or their output is never used are eliminated.
Example:

Code Before Optimization Code After Optimization

i=0;
if (i == 1)
{ i=0;
a=x+5;
}

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

v. Strength Reduction:
In this technique,
As the name suggests, it involves reducing the strength of expressions.
This technique replaces the expensive and costly operators with the
simple and cheaper ones.
Example:

Code Before Optimization Code After Optimization

B=Ax2 B=A+A

Here,
 The expression “A x 2” is replaced with the expression “A + A”.
 This is because the cost of multiplication operator is higher than that of
addition operator.

2. Machine-dependent Optimization
Machine-dependent optimization is done after the target code has been generated and
when the code is transformed according to the target machine architecture. It involves
CPU registers and may have absolute memory references rather than relative references.
Machine-dependent optimizers put efforts to take maximum advantage of memory
hierarchy.

II. LOOP OPTIMIZATION


o Loop optimization is most valuable machine-independent optimization because
program's inner loop takes bulk to time of a programmer.
o If we decrease the number of instructions in an inner loop then the running time of a
program may be improved even if we increase the amount of code outside that loop.
o For loop optimization the following three techniques are important:
i. Code motion
ii. Induction-variable elimination
iii. Strength reduction

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

i. Code motion
 Code motion is used to decrease the amount of code in loop. This
transformation takes a statement or expression which can be moved outside
the loop body without affecting the semantics of the program.
 Example:
In the while statement, the limit-2 equation is a loop invariant equation.
while (i<=limit-2) /*statement does not change limit*/

After code motion the result is as follows:


a= limit-2;
while(i<=a) /*statement does not change limit or a*/

ii. Induction-Variable Elimination


 Induction variable elimination is used to replace variable from inner loop.
 It can reduce the number of additions in a loop. It improves both code space
and run time performance.
 Example:

In this figure, we can replace the assignment t4: = 4*j by t4: = t4-4. The only
problem which will be arose that t4 does not have a value when we enter
block B2 for the first time. So we place a relation t4=4*j on entry to the block
B2.
I. T. S. Engineering College, Greater Noida
Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

iii. Reduction in Strength


 Strength reduction is used to replace the expensive operation by the cheaper
once on the target machine.
 Addition of a constant is cheaper than a multiplication. So we can replace
multiplication with an addition within the loop.
 Multiplication is cheaper than exponentiation. So we can replace
exponentiation with multiplication within the loop.
 Example:

while (i<10)
{
j= 3 * i+1;
a[j]=a[j]-2;
i=i+2;
}

After strength reduction the code will be:


s= 3*i+1;
while (i<10)
{
j=s;
a[j]= a[j]-2;
i=i+2;
s=s+6;
}
In the above code, it is cheaper to compute s=s+6 than j=3 *i

III. BASIC BLOCKS


o Basic block is a set of statements that always executes in a sequence one after the other.
o The characteristics of basic blocks are-
 They do not contain any kind of jump statements in them.
 There is no possibility of branching or getting halt in the middle.
 All the statements execute in the same order they appear.
 They do not lose lose the flow control of the program.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

o EXAMPLE:
1. Three Address Code for the expression a = b + c + d is-

Here,
 All the statements execute in a sequence one after the other.
 Thus, they form a basic block.
2. Three Address Code for the expression If A<B then 1 else 0 is-

Here,
 The statements do not execute in a sequence one after the other.
 Thus, they do not form a basic block.

IV. FLOW GRAPH


o A flow graph is a directed graph with flow control information added to the basic
blocks.
o A control flow graph is used to depict that how the program control is being parsed
among the blocks. It is useful in the loop optimization.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

o EXAMPLE:
1. Compute the basic blocks for the given three address statements-
(1) PROD = 0
(2) I = 1
(3) T2 = addr(A) – 4
(4) T4 = addr(B) – 4
(5) T1 = 4 x I
(6) T3 = T2[T1]
(7) T5 = T4[T1]
(8) T6 = T3 x T5
(9) PROD = PROD + T6
(10) I = I + 1
(11) IF I <=20 GOTO (5)

Solution:
We have-
PROD = 0 is a leader since first statement of the code is a leader.
T1 = 4 x I is a leader since target of the conditional goto statement is a leader.

Now, the given code can be partitioned into two basic blocks as-

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

2. Draw a flow graph for the three address statements given in problem-01.

Solution:
 Firstly, we compute the basic blocks (already done above).
 Secondly, we assign the flow control information.

The required flow graph is-

V. OPTIMIZATION OF BASIC BLOCKS


o Optimization process can be applied on a basic block. While optimization, we
don't need to change the set of expressions computed by the block.

o There are two type of basic block optimization. These are as follows:
i. Structure-Preserving Transformations
ii. Algebraic Transformations

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

i. Structure-Preserving Transformations
 The primary Structure-Preserving Transformation on basic blocks is as follows:
a) Common sub-expression elimination
b) Dead code elimination
c) Renaming of temporary variables
d) Interchange of two independent adjacent statements

a) Common sub-expression elimination


In the common sub-expression, you don't need to be computed it over and
over again. Instead of this you can compute it once and kept in store from
where it's referenced when encountered again.
a:=b+c
b:=a-d
c:=b+c
d:=a-d
In the above expression, the second and forth expression computed the same
expression. So the block can be transformed as follows:
a:=b+c
b:=a-d
c:=b+c
d:=b

b) Dead-code elimination
It is possible that a program contains a large amount of dead code.
This can be caused when once declared and defined once and forget to remove
them in this case they serve no purpose.
Suppose the statement x:= y + z appears in a block and x is dead symbol that
means it will never subsequently used. Then without changing the value of the
basic block you can safely remove this statement.

c) Renaming temporary variables


A statement t:= b + c can be changed to u:= b + c where t is a temporary variable
and u is a new temporary variable. All the instance of t can be replaced with the
u without changing the basic block value.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

d) Interchange of statement
Suppose a block has the following two adjacent statements:
t1 : = b + c
t2 : = x + y
These two statements can be interchanged without affecting the value of block
when value of t1 does not affect the value of t2.

ii. Algebraic Transformations


o In the algebraic transformation, we can change the set of expression into an
algebraically equivalent set. Thus the expression x:= x + 0 or x:= x *1 can be
eliminated from a basic block without changing the set of expression.
o Constant folding is a class of related optimization. Here at compile time, we evaluate
constant expressions and replace the constant expression by their values. Thus the
expression 5*2.7 would be replaced by13.5.
o Sometimes the unexpected common sub expression is generated by the relational
operators like <=, >=, <, >, +, = etc.
o Sometimes associative expression is applied to expose common sub expression
without changing the basic block value. if the source code has the assignments
a:= b + c
e:= c +d +b
o The following intermediate code may be generated:
a:= b + c
t:= c +d
e:= t + b

VI. DAG (DIRECTED ACYCLIC GRAPHS)


o Directed Acyclic Graph (DAG) is a special kind of Abstract Syntax Tree.
o Each node of it contains a unique value.
o It does not contain any cycles in it, hence called Acyclic.
o DAG is a very useful data structure for implementing transformations on Basic Blocks.
o A DAG is usually constructed using Three Address Code.
o Transformations such as dead code elimination and common sub expression
elimination are then applied.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

o PROPERTIES OF DAG:
 Reachability relation forms a partial order in DAGs.
 Both transitive closure & transitive reduction is uniquely defined for DAGs.
 Topological Orderings are defined for DAGs.
o APPLICATIONS OF DAG
DAGs are used for the following purposes-
 To determine the expressions which have been computed more than once
(called common sub-expressions).
 To determine the names whose computation has been done outside the block
but used inside the block.
 To determine the statements of the block whose computed value can be made
available outside the block.
 To simplify the list of Quadruples by not executing the assignment
instructions x:=y unless they are necessary and eliminating the common sub-
expressions.
o CONSTRUCTION OF DAG
 Rule 1:
In a DAG,
 Interior nodes always represent the operators.
 Exterior nodes (leaf nodes) always represent the names, identifiers or
constants.
 Rule 2:
While constructing a DAG,
 A check is made to find if there exists any node with the same value.
 A new node is created only when there does not exist any node with
the same value.
 This action helps in detecting the common sub-expressions and
avoiding the re-computation of the same.
 Rule 3:
The assignment instructions of the form x:=y are not performed unless they
are necessary.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

o EXAMPLES:
1. Consider the following expression and construct a DAG for it-
(a+b)x(a+b+c)
Solution:
Three Address Code for the given expression is-
T1 = a + b
T2 = T1 + c
T3 = T1 x T2
Now, Step wise representation of Directed Acyclic Graph is-
(i) +

a b

(ii) +

+ c

a b

(iii)

2. Consider the following three address


statement: S1:= 4 * i
S2:= a[S1]
S3:= 4 * i
S4:= b[S3]
S5:= s2 * S4
S6:= prod + S5
Prod:= s6

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

S7:= i+1
i := S7
if i<= 20 goto (1)

Solution:

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

VII. GLOBAL DATA FLOW ANALYSIS


o To efficiently optimize the code compiler collects all the information about the
program and distribute this information to each block of the flow graph. This process
is known as data-flow graph analysis.
o Certain optimization can only be achieved by examining the entire program. It can't
be achieved by examining just a portion of the program.
o For this kind of optimization user defined chaining is one particular problem.
o Here using the value of the variable, we try to find out that which definition of a
variable is applicable in a statement.
o EXAMPLES:
1. Based on the local information a compiler can perform some optimizations. For
example, consider the following code:
x = a + b;
x=6*3

 In this code, the first assignment of x is useless. The value computer for x is
never used in the program.
 At compile time the expression 6*3 will be computed, simplifying the second
assignment statement to x = 18;
2. Some optimization needs more global information. For example, consider the
following code:
a = 1;

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

b = 2;
c = 3;
if (. . .) x = a + 5;
else x = b + 4;
c = x + 1;
In this code, at line 3 the initial assignment is useless and x +1 expression can be
simplified as 7.
o But it is less obvious that how a compiler can discover these facts by looking only at
one or two consecutive statements. A more global analysis is required so that the
compiler knows the following things at each point in the program:
 Which variables are guaranteed to have constant values
 Which variables will be used before being redefined

VIII. CODE GENERATION


o The final phase in compiler model is the code generator. It takes as input an
intermediate representation of the source program and produces as output an
equivalent target program. 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.
o The code generated by the compiler is an object code of some lower-level
programming language, for example, assembly language. We have seen that the
source code written in a higher-level language is transformed into a lower-level
language that results in a lower-level object code, which should have the following
minimum properties:
 It should carry the exact meaning of the source code.
 It should be efficient in terms of CPU usage and memory management.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

o A code generator is expected to have an understanding of the target machine’s


runtime environment and its instruction set. The code generator should take the
following things into consideration to generate the code:
 Target language: The code generator has to be aware of the nature of the target
language for which the code is to be transformed. That language may facilitate
some machine-specific instructions to help the compiler generate the code in a
more convenient way. The target machine can have either CISC or RISC
processor architecture.
 IR Type: Intermediate representation has various forms. It can be in Abstract
Syntax Tree (AST) structure, Reverse Polish Notation, or 3-address code.
 Selection of instruction: The code generator takes Intermediate Representation
as input and converts (maps) it into target machine’s instruction set. One
representation can have many ways (instructions) to convert it, so it becomes the
responsibility of the code generator to choose the appropriate instructions wisely.
 Register allocation: A program has a number of values to be maintained during
the execution. The target machine’s architecture may not allow all of the values to
be kept in the CPU memory or registers. Code generator decides what values to
keep in the registers. Also, it decides the registers to be used to keep these values.
 Ordering of instructions: At last, the code generator decides the order in which
the instruction will be executed. It creates schedules for instructions to execute
them.
o DESCRIPTORS:
The code generator has to track both the registers (for availability) and addresses
(location of values) while generating the code. For both of them, the following two
descriptors are used:
 Register descriptor: Register descriptor is used to inform the code generator about
the availability of registers. Register descriptor keeps track of values stored in
each register. Whenever a new register is required during code generation, this
descriptor is consulted for register availability.
 Address descriptor: Values of the names (identifiers) used in the program might
be stored at different locations while in execution. Address descriptors are used to
keep track of memory locations where the values of identifiers are stored. These
locations may include CPU registers, heaps, stacks, memory or a combination of
the mentioned locations.

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

o 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.

o GENERATING CODE FOR ASSIGNMENT STATEMENTS:

1. Consider the three address statement x:= y + z. It can have the following
sequence of codes:
MOV x, R0
ADD y, R0

2. 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

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

Code sequence for the example is as follows:

Statement Code Generated Register Address descriptor


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

IX. ISSUES IN THE DESIGN OF A CODE GENERATOR


The following issues arise during the code generation phase:
1. Input to code generator
2. Target program
3. Memory management
4. Instruction selection
5. Register allocation
6. Evaluation order

1. Input to code generator:


 The input to the code generation consists of the intermediate representation of
the source program produced by front end, together with information in the
symbol table to determine run-time addresses of the data objects denoted by
the names in the intermediate representation.
 Intermediate representation can be:
a. Linear representation such as postfix notation
b. Three address representation such as quadruples
c. Virtual machine representation such as stack machine code

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

d. Graphical representations such as syntax trees and dags.


 Prior to code generation, the front end must be scanned, parsed and translated
into intermediate representation along with necessary type checking.
Therefore, input to code generation is assumed to be error-free.
2. Target program:
 The output of the code generator is the target program. The output may be:
a. Absolute machine language
It can be placed in a fixed memory location and can be executed
immediately.
b. Relocatable machine language
It allows subprograms to be compiled separately.
c. Assembly language
Code generation is made easier.
3. Memory management:
 Names in the source program are mapped to addresses of data objects in
run-time memory by the front end and code generator.
 It makes use of symbol table, that is, a name in a three-address statement
refers to a symbol-table entry for the name.
 Labels in three-address statements have to be converted to addresses of
instructions.
4. Instruction selection:
 The instructions of target machine should be complete and uniform.
 Instruction speeds and machine idioms are important factors when
efficiency of target program is considered.
 The quality of the generated code is determined by its speed and size.
 The former statement can be translated into the latter statement as shown
below:

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

5. Register allocation
 Instructions involving register operands are shorter and faster than those
involving operands in memory.
 The use of registers is subdivided into two sub-problems:
Register allocation – the set of variables that will reside in registers at a
point in the program is selected.
Register assignment – the specific register that a variable will reside in is
picked.
6. Evaluation order
 The order in which the computations are performed can affect the efficiency
of the target code. Some computation orders require fewer registers to hold
intermediate results than others.
X. TARGET MACHINE

o The target computer is a type of byte-addressable machine. It has 4 bytes to a word.


o The target machine has n general purpose registers, R0, R1,..., Rn-1. It also has two-
address instructions of the form:
op source, destination
Where, op is used as an op-code and source and destination are used as a data field.
o It has the following op-codes:
 ADD (add source to destination)
 SUB (subtract source from destination)
 MOV (move source to destination)
o The source and destination of an instruction can be specified by the combination of
registers and memory location with address modes.
Address modes with their assembly-language forms

MODE FORM ADDRESS EXAMPLE ADDED COST

Absolute M M Add R0, R1 1

Register R R Add temp, R1 0

Indexed c(R) C+ contents(R) ADD 100 (R2), R1 1

I. T. S. Engineering College, Greater Noida


Subject: Compiler Design Prachi Jain
Subject Code: KCS 502 Assistant Professor (CSE Dept.)

indirect register *R contents(R) ADD * 100 0

indirect indexed *c(R) contents(c+ (R2), R1 1


contents(R))

Literal #c c ADD #3, R1 1

 Here, cost 1 means that it occupies only one word of memory.


 Each instruction has a cost of 1 plus added costs for the source and destination.
 Instruction cost = 1 + cost is used for source and destination mode.

I. T. S. Engineering College, Greater Noida

You might also like