Unit no4
Define Compiler, Interpreter, Assembler, Linker, Loader, Macro.
1. Compiler
A compiler is a computer program (or a set of programs) that transforms source code written
in a programming language (the source language) into another computer language (the
target language).
Typically, from high level source code to low level machine code or object code.
Unit no4
Interpreter
An interpreter is a common kind of language processor. Instead of producing target program
as a translation, an interpreter appears to directly execute the operations specified in the
source program on inputs supplied by the user.
In contrast, an interpreter reads a statement from the input, converts it to an intermediate
code, execute it, then takes the next statement in sequence.
If an error occurs, an interpreter stops execution and reports it.
Assembler
An assembler translates assembly language programs into machine code. The output of a
assembler is called an object file, which contains a combination of machine instruction as
well as the data required to place these intstructions in memory.
Linker
Linker is a computer program that links and merges various object files together in order to
make an executable file. All these files might have been compiled by separate assembler.
The major task of a linker is to search and locate referenced module/routines in a program
and to determine the memory location where these codes will be loaded making the
program instruction to have absolute reference.
Loader
Loader is a part of operating system and is responsible for loading executable files into
memory and execute them.
It calculates the size of a program (instructions and data) and create memory space for it. It
initializes various registers to initiate execution.
Macro
Macro is a single line abbreviation for group of instructions.
With the help of macro, programmer can define a single "instruction" to represent block of
code.
Unit no4
ASSEMBLER
Assembler is a translator which translates an assembler language program into machine language .
Assembly language program low level language programs which are machine dependents but easier
as compare to machine language.
FEATURES OF AN ASSEMBLY
LANGUAGE
• We can use mnemonic rather than numeric operation code and it also supports an indication of
coding error.
• In this language symbolic operand specification is possible means operand can be represented in the
form of symbolic references rather than machine address of data.
I. Data can be declared by using decimal notation.
The format of an assembly language statement is as follow :-
[label] Mnemonic operand , [operand 1 , operand 2 , _ _ _ _ _ ] The field label is optional.
ELEMENTS OF AN ASSEMBLY
LANGUAGE PROGRAM
An assembly program contain three types of statement :-
1. Imperative statements
2. Declarative statements
3. Assembler Directive statements
Unit no4
Data type :
In this tutorial we will learn Data
types and variables in Assembly
language programming. We will
learn
1. What are code and data
segments/directives?
2. Data types or Data sizes
3. How to create variables in Assembly ?
Segments or Directives:
.data and .code are directives or segments which tells the assembler how to assemble code.
data part holds all the variables and memory related things where as .code holds all the
instructions and code which tells registers and processor what to do.
Data types or Data sizes:
In Assembly language, there are no distinct data types like char,string,int,float,double,etc
Instead there are very basic data types according to their sizes. They are:
1. byte – 8 bits
2. word – 16 bits
3. dword – 32 bits
4. qword – 64 bits
5. Real4 – 32 bit float
6. Real8 – 64 bit float
7. Real10 – 80 bit float
Unit no4
Variables in Assembly language:
To create variables in Assembly language, use one of the above data sizes and allocate
memory for a variable. The general syntax is like this:
<identifier/variable name> <size to allocate> <value>
For creating a variable of 32 bits:
var1 DWORD ?
PASS STRUCTURE OF
ASSEMBLERS
The pass of a language processor is defined as one complete scan of the source program
or it’s equivalent representation .
There are two type of assembler :-
1. Single pass assembler
2. Multi pass assembler
1. SINGLE PASS ASSEMBLER
Unit no4
n assembler pass is one complete scan of source program input to the assembler or equivalent
representation and a translation on a statement by statement basis would be termed as single pass
translation or one pass assembler.
PROGRAM OF SINGLE PASS
ASSEMBLER
ANALYSIS PHASE
Analysis Phase
1. It isolates label, mnemonics and operand field of a statement.
Unit no4
2. It enter symbol found in label field if any and address of text available machine word into symbol
table.
3. It validates the mnemonic by looking it up in to the mnemonic code table.
SYNTHESIS PHASE
1. It obtained machine op code corresponding mnemonic op code by searching mnemonic table.
2. It obtained the machine address of operand symbol table.
3. It makes synthesis of the machine instruction the machine form of constant.
MULTI PASS ASSEMBLER
In multi pass assembler, an assembler goes through assembly language program several times and
generates object code
Unit no4
• First pass second pass and third pass are called as pass1, pass2, pass3 respectively.
• last passed is called as synthesis phase.
• This assembler requires several form of intermediate codes, which are generate by each pass.
COMPARISION BETWEEN SINGLE PASS
& MULTI PASS ASSEMBLER
Single pass assembler Multi pass assembler
Each statement of source program is scanned In multi pass assembler each statement is
by single pass assembler only one times. scanned more than one times
• Single pass assembler is faster than multi pass. Multi pass assembler is slower than single pass
• There is no need to construct intermediate There is need to construct intermediate code
code.
•
• In single pass assembler there is need to the • There is no need to the construct TII.
construct TII.
•
• •
There is no probability of occuring duplication There is a certain amount of duplication in the
action action performed by each pass.
Compiler,Interpreter,Linker,Loader
Regardless of what language you use, you eventually need to convert your program into a language
that the computer can understand
Two ways for doing that:
compile the program or
interpret the program
Unit no4
A compiler is a computer program that translates a program in a source language into an equivalent
program in a target language.
or
Compilers: Translate a source (human-writable) program to an executable (machine-readable)
program
Translate the entire program.
Convert the entire program to machine code, whenthe syntax errors are removed then converted
into the object code
Requires more main memory
Neither source nor the compiler are required for
execution.
Slow for debugging and testing.
Execution time is less.
Unit no4
Security of source code .
Interpreter is a program that executes instructions written in a high-level language
or
Interpreters: Convert a source program and execute it at the same time.
Translate the program line by line.
each time the program is executed ,every line is checked for syntax error & then converted to
equivalent machine code directly.
Requires less main memory
Source program and the interpreter are required forexecution.
Unit no4
Good for fast debugging and testing.
Execution time is more.
No Security of source code
Defination Linker:
A program that takes as input the object files of one or more separately compiled program modules,
and links them together into a complete executable program, resolving reference from one module to
another
Definatin loader:
Unit no4
A program that takes an input an executableprogram, loads it into main memory, and causes
execution to being by loading the correct starting address into the computer register.
When the program finished, control mustsomehow be returned to the operating system.
A single object file might contain machine codefor only one procedure or a set of procedures.
An executable file must contain all the machinecode needed for a particular program; it must
contain the address of the first instruction to be executed
1. Absolute loader: absolute loader is a primitive type of loader which does only the loading function. It
does not perform linking and program relocation.
2. Bootstrap loader: when the computer is turned on absolute loader is executed. this loader is
responsible for loading the operating system and transferring control to it. This loader is present in the
ROM area of main memory.
3. Relocateabel loader: this loader is responsible for relocation and loading.
1. Linking loader: this linker performs all the linking and relocation operations and load the linked
program directly into the main memory.
2. Linkage editor: this linker produces a linked version of the program called as a load module or an
executable image.
Unit no4
3. Dynamic linker: this. Scheme postpone the linking function until execution time. Any subroutine is
loaded and linked to the rest of program when it is first called.
Difference between Compiler and Interpreter. Compiler vs Interpreter
Compiler: A compiler is a computer program(or a set of program) that transforms source
code written in a programming language into another computer language(the target
language).
Interpreter: An interpreter is a common kind of language processor
Compiler Interpreter
A compiler is a computer program(or a An interpreter is a common kind of language
set of program) that transforms source processor, instead of producing a target program
code written in a programming language as a translation an interpreter appears to directly
into another computer language(the execute the operations specified in the source
target language). program on inputs supplied by the user.
Compiler works on the complete Interpreter program works line-by-line. It takes
program at once. It takes the entire one statement at a time as input.
program as input.
Compiler generate the intermediate code Interpreter does not generate intermediate code.
called as object code or machine code.
Compiler executes conditional control Interpreter executes conditional control
statements(like if-else and switch case) statements at a slower rate.
faster than interpreter.
It takes more memory since the entire Interpreted programs are more memory efficient
compiled code(object code) has to be as they do not generate any object code.
reside in memory.
Compile once and run anytime, they Interpreted programs are interpreted line-by-line
doesn't need to run eveytime. every time they are run.
Unit no4
Errors are reported after the whole Errors are reported as soon as the first error is
program is checked for syntactical and encountered. Rest of the program will not be
other errors. checked until the existing error is removed.
A compiled language is more difficult to Debugging is easy because interpreter stops and
debug. reports errors as it encounter them.
Compiler does not allow a program to Interpreter runs the program from first line and
run until it is completely error free. stops execution only if it encounters an error.
Compiled language are more efficient but Interpreted language are less efficient but easy to
difficult ot debug. debug.
Examples of programming languages that Examples of programming languages that use
use compiler are C, C++, COBOL, interpreter are BASIC, Python, PHP, Perl, LISP.
JAVA.