Programming Languages ( High level, Low level and Machine Language) and Translators ( Compiler, Interpreter, Assembler)
Programming Languages
A Programming Language consists of a set of vocabulary and grammatical rules, to express the computations and tasks that the computer has to perform. Programming languages are used to write a program, which controls the behavior of computer, codify the algorithms precisely, or enables the human-computer interface. Each language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions.
The programming language should be understood, both by the programmer (who is writing the program) and the computer. A computer understands the language of 0∙s and 1∙s, while the programmer is more comfortable with English-like language. Programming Language usually refers to high-level languages like COBOL, BASIC, FORTRAN,BCPL, C, C++, Java,Python etc. High level programming language is chosen depending on the type of the application you are going to develop.For example if we are developing android mobile applications we use programming languages like Kotlin.
Programming languages fall into three categories
Machine Language is what the computer can understand but it is difficult for the programmer to understand. Machine languages consist of numbers only(1 and 0). Each kind of CPU has its own unique machine language.
Assembly Language falls in between machine language and high-level language. They are similar to machine language, but easier to program in, because they allow the programmer to substitute names for numbers.
High-level Language is easier to understand and use for the programmer but difficult for the computer.
Regardless of the programming language used, the program needs to be converted into machine language so that the computer can understand it. In order to do this a program is either compiled or interpreted.
Figure below shows the hierarchy of programming languages. The choice of programming language for writing a program depends on the functionality required from the program and the kind of program to be written. Machine languages and assembly languages are also called low-level languages, and are generally used to write the system software. Application software is usually written in high-level languages. The program written in a programming language is also called the source code.
Machine Language
A program written in machine language is a collection of binary digits or bits that the computer reads and interprets. It is a system of instructions and data executed directly by a computer∙s CPU. It is also referred to as machine code or object code. It is written as strings of 0’s and 1∙s, as shown in Figure below.
Some of the features of a program written in machine language are as follows:
- The computer can understand the programs written in machine language directly. No translation of the program is needed.
- Program written in machine language can be executed very fast (Since no translation is required).
- Machine language is defined by the hardware of a computer. It depends on the type of the processor or processor family that the computer uses, and is thus machine-dependent. A machine- level program written on one computer may not work on another computer with a different processor.
- Computers may also differ in other details, such as memory arrangement, operating systems, and peripheral devices; because a program normally relies on such factors, different computer may not run the same machine language program, even when the same type of processor is used.
- Most machine-level instructions have one or more opcode fields which specify the basic instruction type (such as arithmetic, logical, jump, etc), the actual operation (such as add or compare), and some other fields.
- It is difficult to write a program in machine language as it has to be written in binary code. For e.g., 00010001 11001001. Such programs are also difficult to modify.
- Since writing programs in machine language is very difficult, programs are hardly written in machine language.
Assembly Language
A program written in assembly language uses symbolic representation of machine codes needed to program a particular processor (CPU) or processor family. This representation is usually defined by the CPU manufacturer, and is based on abbreviations (called mnemonics) that help the programmer remember individual instructions, registers, etc. Small, English-like representation is used to write the program in assembly language, as shown in Figure below.
Some of the features of a program written in assembly language are as follows:
- Assembly language programs are easier to write than the machine language programs, since assembly language programs use short, English-like representation of machine code. For e.g.:
LOAD A
SUB A, B
- The program written in assembly language is the source code, which has to be converted into machine code, also called object code, using translator software, namely, assembler.
- Each line of the assembly language program is converted into one or more lines of machine code. Hence assembly language programs are also machine-dependent.
- Although assembly language programs use symbolic representation, they are still difficult to write.
- Assembly language programs are generally written where the efficiency and the speed of program are the critical issues, i.e. programs requiring high speed and efficiency.
High-level Language
A program in a high-level language is written in English-like language. Such languages hide the details of CPU operations and are easily portable across computers. A high-level language isolates the execution semantics of computer architecture from the specification of the program, making the process of developing a program simpler and more understandable with respect to assembly and machine level languages. Some of the features of a program written in high-level language are as follows:
- Programs are easier to write, read or understand in high-level languages than in machine language or assembly language.
- Programs written in high-level languages is the source code which is converted into the object code (machine code) using translator software like interpreter or compiler.
- A line of code in high-level program may correspond to more than one line of machine code.
- Programs written in high-level languages are easily portable from one computer to another.
Translators
Translator software is used to convert a program written in high-level language and assembly language to a form that the computer can understand. Translator software converts a program written in assembly language, and high-level language to a machine-level language program .The translated program is called the object code. There are three different kind of translator software.
- Assembler,
- Compiler, and
- Interpreter.
Assembler converts a program written in assembly language to machine language. Compiler and interpreter convert a program written in high-level language to machine language. Let’s now discuss, briefly, the different kinds of translator software.
Assembler
Assembly language is also referred to as a symbolic representation of the machine code. Assembler is a software that converts a program written in assembly language into machine code. There is usually a one-to-one correspondence between simple assembly statements and machine language instructions. The machine language is dependent on the processor architecture, though computers are generally able to carry out the same functionality in different ways. Thus the corresponding assembly language programs also differ for different computer architectures.
It uses opcode for the instructions. An opcode basically gives information about the particular instruction. The symbolic representation of the opcode (machine level instruction) is called mnemonics. Programmers use them to remember the operations in assembly language.
For example ADD A,B
Here, ADD is the mnemonic that tells the processor that it has to perform addition function. Moreover, A and B are the operands. Also, SUB, MUL, DIVC, etc. are other mnemonics.
Example:GAS(GNU Assembler),MASM,NASM Etc...
See the comparison of assemblers here https://en.wikipedia.org/wiki/Comparison_of_assemblers
Compiler
A program written in a high-level language has to be converted to a language that the computer can understand, i.e. binary form. Compiler is the software that translates the program written in a high-level language to machine language. The program written in high-level language is referred to as the source code and compiled program is referred as the object code. The object code is the executable code, which can run as a stand-alone code. It does not require the compiler to be present during execution. Each programming language has its own compiler.
Some languages that use a compiler are C,C++, COBOL, Pascal, and FORTRAN. In some languages, compilation using the compiler and linking using the linker are required for creating the executable object code.
The compilation process generally involves two parts—breaking down the source code into small pieces and creating an intermediate representation, and, constructing the object code for the intermediate representation. The compiler also reports syntax errors, if any, in the source code.
Interpreter
The purpose of interpreter is similar to that of a compiler. The interpreter is used to convert the high-level language program into computer-understandable form. However, the interpreter functions in a different way than a compiler. Interpreter performs line-by-line execution of the source code during program execution. Interpreter reads the source code line-by-line, converts it into machine understandable form, executes the line, and then proceeds to the next line.
Example: BASIC,Python, Rubi
Difference Between a Compiler and An Interpreter
Compiler and Interpreter are used to convert a program written in high-level language to machine language; however, they work differently. The key differences between a compiler and an interpreter are as follows:
- Interpreter looks at a source code line-by-line. Compiler looks at the entire source code.
- Debugging is easy in Interpreter
- Interpreter converts a line into machine executable form, executes the line, and proceeds with the next line. Compiler converts the entire source code into object-code and creates the object code. The object code is then executed by the user.
- Compiler requires lot of memory
- For a given source code, once it is compiled, the object code is created. This object code can be executed multiple number of times by the user. However, interpreter executes line-by-line, so executing the program using an interpreter means that during each execution, the source code is first interpreted and then executed.
- During execution of an object code, the compiler is not required. However, for interpretation, both interpreter and the source code is required during execution (because source code is interpreted during execution).
- Since interpreter interprets line-by-line, the interpreted code runs slower than the compiled code.
- Compilers are more secure
- C,C++,Java uses compilers where as Python, Perl,Ruby uses interpreter.
Linker
Linker is a program that links several object modules and libraries to a single executable program. A source code of a program is often very large consisting of several hundred or more lines. The source code may also include reference to libraries. All these independent modules may not be stored in a single object file. The code is broken down into many independent modules for easy debugging and maintenance. Before execution of the program, these modules and the required libraries are linked together using the linker software. The compiled and the linked program are called the executable code.
Loader
The loader software is used to load and re-locate the executable program in the main memory. Software has to be loaded into the main memory during execution. Loader assigns storage space to the program in the main memory for execution.
Difference between Linker and Loader
S.No. | LINKER | LOADER |
1 | A linker is an important utility program that takes the object files, produced by the assembler and compiler, and other code to join them into a single executable file. | A loader is a vital component of an operating system that is accountable for loading programs and libraries. |
2 | It uses an input of object code produced by the assembler and compiler. | It uses an input of executable files produced by the linker. |
3 | The foremost purpose of a linker is to produce executable files. | The foremost purpose of a loader is to load executable files to memory. |
4 | Linker is used to join all the modules. | Loader is used to allocate the address to executable files. |
5 | It is accountable for managing objects in the program’s space. | It is accountable for setting up references that are utilized in the program. |
Comments
Post a Comment