C - Low Level Programming
Machine Language vs Assembly Language vs Programming Language
Computer can understand only zeros and ones. This binary code is known as machine language. In early days, the programmers used to write programs directly in assembly language. Then, the program was then converted to machine language. Later, they felt that writing a program in assembly language was a very tedious job. So, Programming languages were developed to write code much more easily.
In the beginning, assembly languages were developed. These languages used simple mnemonic instructions to write a program. These instructions are directly mapped to a sequence of machine language operations. For example:
- MOV R1, R2 - moves the data from register R2 to register R1.
- ADD R1, R2 - add the content of register R1 and R2.
The assembly language is a considerable improvement on raw binary. This assembly language program is a non-portable one. That is, the program developed for one type of machine does not work on another type of machine. Hence, code had to written separately for each type of machine
In 1950s and 60s, the high-level and low level programming languages were developed. For writing the programs, these languages use the mechanism like looping construct, conditional construct and so on. It provides proper structure for a program which makes the user to understand the progress of the instruction flow.
Programming language divides the large program into number of small modules and each module can do the particular operation and finally these modules are combined together to produce the final result. Program written in such language tend to be relatively portable. That means, program written on one machine can be run on most other machines.
We can write the program using either high-level or low level language. This written program is called source code and is not directly executed on the computer. Instead, the written source code needs to be converted into binary code. This is done by the another translating program such as assembler, compiler or interpreter.
This is the program which translates the program written in assembly language into machine code. Computers can execute the machine code without any change.
A Compiler translates the source program (written code) into machine specific assembly language code (object code), which is then converted to machine code by an assembler. Compiler can read the complete source code, convert it into the assembly code and produce the error report, if any, to the user. Compiler takes small amount of time for converting source code to object code. C and C++ languages uses a compiler to convert C/C++ language source code (.c or .cpp file) into an executable (.exe) file
Interpreter directly executes the code. Input to the interpreter can be a language code like BASIC or LISP. In other cases, it can be bytecode like in Java. In case of language like BASIC, No conversion to machine language is done. Since interpreter directly executes, even syntax errors are thrown at runtime only and then the program stops. In case of Java, a compiler compiles the codes and indicates all the errors. Once the programmer/coder/developer fixes the errors, the bytecode is generated in a file with extension .class. In case of C, we do not use an interpreter.