Documente Academic
Documente Profesional
Documente Cultură
Programming Languages
Lecture 3
Topic
Review Compilation Interpretation Assembler Compilation Phases Machine-dependent and Machine-independent Summary
Overview of Compilation
program gcd(input, output); var i, j: integer; begin
read(i, j);
while i <> j do if i > j then i := i j; else j := j i; writeln(i) end.
Compilation
Compilation
A Compiler is a program that reads a program written in one language (the source language) and translates it into an equivalent program in another language (the target language).
Machine code [a = a + b ;] [1000101001111]
Interpretation
Interpreters: A program that translates a users high-level program (Source Program) into machine program ( Target Program) at the same time.
Assembler
A program that converts a program written in assembly language into machine code.
Assembly Language
Assembler
Source Program Preprocessor Modified Source Program Compiler Target Assembly Program Assembler Relocatable Machine Code Loader / Linker-editor Absolute Machine Code Library , Relocatable Object Files
Language
Processing System
Compilation Phases
Position
= initial
+
rate * 60 ;
Expression
Expression
+
identifier
rate
Expression
Expression
Number
60
For example, a real number is used to index an or when a binary arithmetic operator is applied to an integer and real.
=
Position initial
= + *
rate
60 Position initial rate
+ * inttoreal
60.0
We can think of this intermediate representation as a program for an abstract machine. This intermediate representation should have two important properties;
it should be easy to produce, and easy to translate into the target program.
temp1 = inttoreal(60)
temp2 = id3 * temp1
temp1 = inttoreal(60) temp2 = id3 * temp1 temp3 = id2 + temp2 id1 =temp3 After perform Optimization temp1 = id3 * 60.0 id1 = id2+ temp1
Then, intermediate instructions are each translated into a sequence of machine instructions that perform the same task.
MOVF MULF MOVF id3, R2 #60.0, R2 id2, R1
ADDF
MOVF
R2, R1
R1, id1
Machine-dependent
and Machine-independent
Machine-dependent
is a term for application software that runs only on a particular type of computer.
machine-independent
A term applied to software that is not dependent on the properties of a particular machine, and can therefore be used on any machine. Also called machine-independent, or cross-platform , portable.
end