As stated earlier, programmers write programs by using a source language, which can be either a high-level language or an assembly language; however, a computer cannot understand both these types of programming languages. Therefore, programs written in these types of languages need to be first converted into the machine language code. To convert the source code of a program into machine language code, a language converter is required.
Let's try to understand the need of language converter with the help of an example. If a German and a Russian talk to each other in their own languages, it would not make any sense to any of them. The German will not be able to understand a single word spoken by the Russian. Similarly, the Russian will also not be understand a single word spoken by the German. Therefore, they will need a third person who can translate everything spoken in German into Russian and everything spoken in Russian into German.
Now, let's compare this situation with our problem relating to source language and machine language. When a program is written in a high-level language or the assembly, a computer cannot understand it. The computer would understand a program written in machine language only. Therefore, similar to the Russian and German persons, a program written in the high-level language or assembly language needs another program that can convert the source code of the program into machine language code.
Let's now understand how the conversion of source code from a high-level language to the machine language and the assembly language to the machine language takes place.
High-Level Language to Machine Language Conversion
As stated earlier, programs written by using a high-level language are not understood by a computer.Therefore, such programs need to be converted into the machine language code so that a computer can understand them. Conversion of code from high-level language to machine language is done with the help of the following two language converters:
⦁Compiler: Converts a complete program from a high-level language to machine language. If an error is caught by the compiler in the program during conversion, then the user. On the other hand, if the compiler does not find any error in the program, them the compiler executes the program.
⦁Interpreter: Converts the code written in a high-level language into machine language code, line by line. If the interpreter finds an error in the first line of code during conversion, it displays the error to the user. On the other hand, if the interpreter does not find any error in the first line of code, then the second line of the code is checked. The same process is followed for the remaining lines of the code as well. Since an interpreter interprets the programs code line by line: therefore, it takes more time to convert a program than the compiler.
The process of converting the program code from a high-level language to the machine language is shown in Fig.IP-1.1:
Assembly Language to Machine Language Conversion
The conversion of assembly language code into machine language code is done through another assembly language into machine instrucions, one by one. The conversion of code from the assembly language to the machine language is shown in Fig.IP-1.2:
You have learned how the program written in the source language is converted into the machine language code. The next section explains the various stages of program development cycle.