Computer Languages
Over the years, computer
languages have been evolved from Low-Level to High-Level Languages. In the
earliest days of computers, only Binary Language was used to write programs.
The computer languages are classified as follows:
Machine Language (low level language)
Low-Level language is the only language which can be
understood by the computer. Low-level language is also known as Machine
Language. The machine language contains only two symbols 1 & 0.
All the instructions of machine language are written in the form of binary
numbers 1's & 0's. A computer can directly understand the machine language.
Assembly Language (middle level language)
Middle-level language is a
computer language in which the instructions are created using symbols such as
letters, digits and special characters. Assembly language is
an example of middle-level language. In assembly language, we use predefined
words called mnemonics. Binary code instructions in low-level language are
replaced with mnemonics and operands in middle-level language. But the computer
cannot understand mnemonics, so we use a translator called Assembler to
translate mnemonics into machine language.
Assembler is a translator
which takes assembly code as input and produces machine code as output. That
means, the computer cannot understand middle-level language, so it needs to be
translated into a low-level language to make it understandable by the computer.
Assembler is used to translate middle-level language into low-level language.
g++ -S main.cpp -o main.s
High Level Language
High-level language is a
computer language which can be understood by the users. The high-level language
is very similar to human languages and has a set of grammar rules that are used
to make instructions more easily. Every high-level language has a set of
predefined words known as Keywords and a set of rules known as Syntax to create
instructions. The high-level language is easier to understand for the users but
the computer can not understand it. High-level language needs to be converted
into the low-level language to make it understandable by the computer. We
use Compiler or interpreter to convert
high-level language to low-level language.
Languages like FORTRAN, C,
C++, JAVA, Python, etc., are examples of high-level languages. All these
programming languages use human-understandable language like English to write
program instructions. These instructions are converted to low-level language by
the compiler or interperter so that it can be understood by the computer.
g++ main.cpp
Compilers
A compiler takes the source code as a whole and
translates it into object code all in one go. Once converted, the object code
can be run at any time. This process is called compilation.
All of the object files used in a program must be
combined before the program can be run. This is done using a linker tool, which
takes one or more objects and groups them into a single executable or
a library.
Compilers have several advantages:
·
Compiled programs run quickly
since they have already been translated.
·
A compiled program can be
supplied as an executable file. An executable file is a file that is ready to
run. Since an executable file cannot be easily modified, programmers prefer to
supply executables rather than source code.
·
Compilers optimise code.
Optimised code can run quicker and take up less memory space.
Compilers have several disadvantages:
·
Because the source code is
translated as a whole, there must be enough memory space to hold the source
code, the compiler and the generated object code. There also needs to be
temporary working space for the compiler to perform the translation. Modern
systems either have enough memory or use virtual memory to hold all
the data.
·
Compilers do not usually spot
errors - the program has to be compiled and run before errors are encountered.
This makes it harder to see where the errors lie.
·
The source code must be
recompiled every time the programmer changes the program.
·
Source code compiled on one
platform will not run on another - the object code is specific to the processor's architecture.
Interpreters
An interpreter translates source code into object code
one instruction at a time. It is similar to a human translator
translating what a person says into another language, sentence by sentence. The
resulting object code is then executed immediately. The process is
called interpretation.
Interpreters have several advantages:
·
Instructions are executed as
soon as they are translated.
·
Since instructions are
executed once translated, they are not stored for later use. As a result,
interpreters require less available memory.
·
Errors can be spotted quickly.
Once an error is found, the program stops running and the user is notified at
which part of the program the interpretation has failed. This makes
interpreters extremely useful when developing programs.
Interpreters also have several disadvantages:
·
Interpreted programs run more
slowly. The processor has to wait for each instruction to be translated before
it can be executed.
·
Additionally, the program has
to be translated every time it is run.
·
Interpreters do not produce an
executable file that can be distributed. As a result, the source code program
has to be supplied and this could be modified without permission.
·
Interpreters do not optimise
code - the translated code is executed as it is.
Assemblers
Assemblers are a third type of translator. The purpose of
an assembler is to translate assembly language into object code.
Whereas compilers and interpreters generate many machine
code instructions for each high-level instruction, assemblers create one
machine code instruction for each assembly instruction.
0 comments:
Post a Comment