PHN-314 video assignment
A high-level language is a programming language such as C, that enables a programmer to write programs that are more or less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages and further from machine languages.
The main advantage of high-level languages over low-level languages is that they are easier to read, write, and maintain. Ultimately, programs written in a high-level language must be translated into machine language by a compiler or interpreter.
A low-level language is a programming language that provides little or no abstraction of programming concepts and is very close to writing actual machine instructions. Two examples of low-level languages are assembly and machine code.
So we know machines understand binary language and us humans understand English or various other languages except for binary. So the ques is how do we communicate.??
If you are a human, there is a very high probability that you gonna use a high-level language to write your code.
Let us understand how this high-level code get converted to machine-readable binary code
Let us create a hello world file and understand what happens under the hood while executing this program
We will create this program and see the intermediate files
We compile our hello world file to see the following on screen
In the first command, we compiled and saved all the temporary files made in between out high-level text file written in C (world.c) and the output low-level binary file (world).
what are these three files?
let us understand by understanding what goes inside a compilation process
The compiler converts a C program into an executable. There are four phases for a C program to become an executable machine code:
1-Pre-processing
2-Compilation
3-Assembly
4-Linking
Pre-processing
This is the first phase through which source code is passed. This phase includes:
The preprocessed output is stored in the world.i
Let’s see what’s inside world.i using $vi world.i
In the above output, the source file is filled with lots and lots of info, but in the end our code is preserved.
Analysis:
Compiling
The next step is to compile world.i and produce an intermediate compiled output file world.s. This file is in assembly level instructions. Let’s see through this file using $vi world.s
The snapshot shows that it is in assembly language, which assembler can understand.
Assembly
In this phase, the world.s is taken as input and turned into world.o by assembler. This file contains machine-level instructions. At this phase, only the existing code is converted into machine language. Let’s view this file using $vi world.o
Linking
This is the final phase in which all the linking of function calls with their definitions are done. Linker knows where all these functions are implemented. Linker does some extra work also, it adds some extra code to our program which is required when the program starts and ends. For example, there is a code which is required for setting up the environment like passing command line arguments.
Having converted our codes to low-level machine binary code let us understand how this code is understood by a microprocessor
The processor contains billions of transistors and these transistors are connected to form circuitry that can perform a number of operations like addition, subtraction, comparison etc. but the correct circuitry only gets connected together when the corresponding instruction gets fed into the microprocessor. Example the opcode 80H in 8085 corresponds to ADD B which means that the bits stored in register B are added with the bits stored in the accumulator.
The 1s and 0s in the instruction 80H cause certain transistors inside the processor to open or close in such a way that that accumulator and register B get added and the result gets stored in the accumulator itself.
This is the hiearchy that our code follows
A Life Without Microprocessor
Invention of the century