Documente Academic
Documente Profesional
Documente Cultură
= Computers are digital devices. All types of commands, data and instructions required to be
converted into machine code which is the combination of 0s and 1s. So, we give instructions to
the computer in a language which is similar to English and easier for us to understand. The
computer translates these instructions into the machine language with the help o language
translators. Language translators are of three types.
(i) Assembler: An assembler is software that converts programs written in assembly language to
machine language.
(ii) Interpreter: An interpreter is software that converts programs written in high level language
to machine language code. It converts one instruction at a time.
(iii) Compiler: A compiler is software that converts programs written in high level language to
machine code in a single operation.
Compiler scans the entire program once and then converts it into machine
language which can then be executed by computer's processor.In short
compiler translates the entire program in one go and then executes it.
Interpreter on the other hand first converts high level language into an
intermediate code and then executes it line by line. This intermediate code is
executed by another program.
Diagrammatic representation-
What is Assembler?
Assembler is used for converting the code of low level language (assembly
language) into machine level language.If you have worked on microprocessors like
8085 and 8086 the module which converts assembly language into machine
language is nothing but Assembler.
Finally when you run java HelloWorld java interpreter is invoked which
reads these bytecodes line by line, convert it into machine language and
execute it.
This is why Java is called as both compiled as well as interpreted language. But this
is not all. There is another concept called - Just-in-time compilation
JIT(Just-in-time compilation)
You can read the wiki page for complete details but here I am only going to provide
relevant points from Java perspective.
JIT as the name suggests does just in time or on the fly compilation of
java byte codes to native machine language that can be directly
executed by the processor.
JIT compiler runs only after the program(JVM) has started. so it has access to
dynamic runtime information whereas a standard compiler doesn't and can
make better optimizations like inlining functions that are used frequently.
But question may arise - Addition time is spent every time to compile the
code?
Yes it is true if we use pure JIT then additional time is spent compiling every time
code is run and hence a new technique was introduced - HotSpot Compiling. In this
But if the count of execution exceeds a limit the corresponding byte codes
are compiled to machine code by JIT and are directly executed thereafter.
Java compiler (javac) converts Java code to byte code and then Java
interpreter (java) interprets bytecodes line by line, converts it into native
code and executes it.
Yes this will have an additional overhead in terms of time and memory
footprint as JIT performs optimizations and compilation into native code on
the fly (as your application is running) but subsequent calls to that part of
code are efficient and fast.
Assembler: A computer will not understand any program written in a language, other than its
machine language. The programs written in other languages must be translated into the machine
language. Such translation is performed with the help of software. A program which translates an
assembly language program into a machine language program is called an assembler. If an
assembler which runs on a computer and produces the machine codes for the same computer
then it is called self assembler or resident assembler. If an assembler that runs on a computer and
produces the machine codes for other computer then it is called Cross Assembler.
Assemblers are further divided into two types: One Pass Assembler and Two Pass
Assembler. One pass assembler is the assembler which assigns the memory addresses to the
variables and translates the source code into machine code in the first pass simultaneously. A
Two Pass Assembler is the assembler which reads the source code twice. In the first pass, it reads
all the variables and assigns them memory addresses. In the second pass, it reads the source code
and translates the code into object code.
Compiler: It is a program which translates a high level language program into a machine
language program. A compiler is more intelligent than an assembler. It checks all kinds of limits,
ranges, errors etc. But its program run time is more and occupies a larger part of the memory. It
has slow speed. Because a compiler goes through the entire program and then translates the
entire program into machine codes. If a compiler runs on a computer and produces the machine
codes for the same computer then it is known as a self compiler or resident compiler. On the
other hand, if a compiler runs on a computer and produces the machine codes for other computer
then it is known as a cross compiler.
Interpreter: An interpreter is a program which translates statements of a program into machine
code. It translates only one statement of the program at a time. It reads only one statement of
program, translates it and executes it. Then it reads the next statement of the program again
translates it and executes it. In this way it proceeds further till all the statements are translated
and executed. On the other hand, a compiler goes through the entire program and then translates
the entire program into machine codes. A compiler is 5 to 25 times faster than an interpreter.
By the compiler, the machine codes are saved permanently for future reference.
On the other hand, the machine codes produced by interpreter are not saved. An interpreter is a
small program as compared to compiler. It occupies less memory space, so it can be used in a
smaller system which has limited memory space.
Linker: In high level languages, some built in header files or libraries are stored. These libraries
are predefined and these contain basic functions which are essential for executing the program.
These functions are linked to the libraries by a program called Linker. If linker does not find a
library of a function then it informs to compiler and then compiler generates an error. The
compiler automatically invokes the linker as the last step in compiling a program.
Not built in libraries, it also links the user defined functions to the user defined
libraries. Usually a longer program is divided into smaller subprograms called modules. And
these modules must be combined to execute the program. The process of combining the modules
is done by the linker.
Related Links
What is an Compiler?
What is an Assembler?
Assembler is software or a tool that translates Assembly language
to machine code. So, an assembler is a type of a compiler and the
source code is written in Assembly language. Assembly is a human
readable language but it typically has a one to one relationship
with the corresponding machine code. Therefore an assembler is
said to perform isomorphic (one to one mapping) translation.
Advanced assemblers provide additional features that support
program development and debugging processes. For example, the
type of assemblers called macro assemblers provides a macro
facility.
What is an Interpreter?
An interpreter is a computer program or a tool that executes
programming instructions. An interpreter may either execute the
source code directly or converts the source to an intermediate
code and execute it directly or execute precompiled code produced
by a compiler (some interpreter systems include a compiler for
this task). Languages like Perl, Python, MATLAB and Ruby are
examples of programming languages that use an intermediate code.
UCSD Pascal interprets a precompiled code. Languages like Java,
BASIC and Samltalk first compile the source to an intermediate
code called bytecode and then interpret it.
What is a Debugger?
Debugger is a computer program that is used to find bugs/errors
in other programs. Debugger allows executing a program and
inspecting each step in the program execution. It also allows
Interpreter
1.Compiler translates a high level language program into machine level language.
2.It takes one statement of a high level language program, translates it into machine language
instructions and immediately executes it.
3.a one to one relationship with the corresponding machine code
4.Languages like Java, BASIC and Samlltalk first compile the source to an intermediate code called
bytecode and then interpret it.
Assembler
1.Assembler translates a assembly language program into machine level language.
2.It takes one statement of a assembly language program, translates it into machine language
instructions and immediately executes it.
3.typically has a one to one relationship with the corresponding machine code