34. Machine code instruction and linking
20 May 2020 | CS
Machine code instruction.
-
A modern-day computers are “digital machines” and computer hardware has been designed to handle and process data only in digital form. Every computer system has a microprocessor which acts as brain of computer system. the processor is the main components in computer system which performs all the calculations and logical operations.
-
the program code which computer’s CPU can directly interpret and execute without any need for conversion or translation is referred as machine code or machine language. A CPU can understand and execute instructions only in machine langue.
-
A machine code is not considered to be human readable but it is considered as machine readable because it only contains sequence or patterns in binary
-
A compiler convert the program source doe into its equivalent machine code in binary which is referred as object code.
-
the main purpose of the compilation process is to create a stand alone executable file which can run on a specific platform for which it has been compiled.
Program compilation
-
the process of converting the program source code written in high level programming language into the machine code executable file is generally referred as compilation. however, the compiler only converts source code in to Object code which consist of machine instructions in binary. A compiler may produce more than one object code files after the compilation.
-
the compiler only convert the source code into the Object code. the Object code cannot be directly executed by the operating system. the Object code file needs to be further processed by another program called “Linker” which is built into the compiler.
-
the compiler may produce number of object code files for a single source code file. the object code consist of machine code instructions in binary which is equivalent of corresponding high level program instructions in program source file. therefore, linking is need to link all object code files and other files together to create an “Executable” file.
Linking
-
the large computer programs are organized in number of files. the user defined functions are written in a separate files. the files are tied to the main program file in the header section such as #include in C langue.
-
Similarly, the programming language also provides library of standard functions in precompiled object code format which programmer can readily use to simplify the programming jobs.
-
the programmer can use these user defined functions and standard function library by simply including these files in the beginning of the program header section. since the standard library code is in the object code form which is a precompiled format and can be directly included in the linking stage by the linker while creating an executable file during the program compilation process.
-
the Linker plays a crucial role in software development because it allows sperate compilation of program modules. instead of organizing a large application as one monolithic source file, we can split the program it into smaller files which are more manageable modules that can be easily modified and compiled separately.
-
the modular approach has many advantages. if we change one of these module, we need to simply recompile and re-link only one module that has changed. No need to recompile the entire program.
-
the linking is a final stage of the compilation process in which multiple Object code files, other reference and library references are linked together to create a single “Executable” file.
-
the linker is also just another program. Linker reads in several files, the object file that was generated by the compiler and one or more library files. in the linking step the library references are taken care of
-
the compiler while compiling doesn’t resolve the library references. all the library references are resolved at the linking stage by the linker.
-
Every time linker finds a reference to a library routine in the object file, it reads the library files, then find that routine and replaces the programmer’s reference with the actual code for the routine from the library file. after it has replaced all the references with actual code from the library, the linker then creates an executable binary file which can be executed by OS
Machine code instruction.
-
A modern-day computers are “digital machines” and computer hardware has been designed to handle and process data only in digital form. Every computer system has a microprocessor which acts as brain of computer system. the processor is the main components in computer system which performs all the calculations and logical operations.
-
the program code which computer’s CPU can directly interpret and execute without any need for conversion or translation is referred as machine code or machine language. A CPU can understand and execute instructions only in machine langue.
-
A machine code is not considered to be human readable but it is considered as machine readable because it only contains sequence or patterns in binary
-
A compiler convert the program source doe into its equivalent machine code in binary which is referred as object code.
-
the main purpose of the compilation process is to create a stand alone executable file which can run on a specific platform for which it has been compiled.
Program compilation
-
the process of converting the program source code written in high level programming language into the machine code executable file is generally referred as compilation. however, the compiler only converts source code in to Object code which consist of machine instructions in binary. A compiler may produce more than one object code files after the compilation.
-
the compiler only convert the source code into the Object code. the Object code cannot be directly executed by the operating system. the Object code file needs to be further processed by another program called “Linker” which is built into the compiler.
-
the compiler may produce number of object code files for a single source code file. the object code consist of machine code instructions in binary which is equivalent of corresponding high level program instructions in program source file. therefore, linking is need to link all object code files and other files together to create an “Executable” file.
Linking
-
the large computer programs are organized in number of files. the user defined functions are written in a separate files. the files are tied to the main program file in the header section such as #include in C langue.
-
Similarly, the programming language also provides library of standard functions in precompiled object code format which programmer can readily use to simplify the programming jobs.
-
the programmer can use these user defined functions and standard function library by simply including these files in the beginning of the program header section. since the standard library code is in the object code form which is a precompiled format and can be directly included in the linking stage by the linker while creating an executable file during the program compilation process.
-
the Linker plays a crucial role in software development because it allows sperate compilation of program modules. instead of organizing a large application as one monolithic source file, we can split the program it into smaller files which are more manageable modules that can be easily modified and compiled separately.
-
the modular approach has many advantages. if we change one of these module, we need to simply recompile and re-link only one module that has changed. No need to recompile the entire program.
-
the linking is a final stage of the compilation process in which multiple Object code files, other reference and library references are linked together to create a single “Executable” file.
-
the linker is also just another program. Linker reads in several files, the object file that was generated by the compiler and one or more library files. in the linking step the library references are taken care of
-
the compiler while compiling doesn’t resolve the library references. all the library references are resolved at the linking stage by the linker.
-
Every time linker finds a reference to a library routine in the object file, it reads the library files, then find that routine and replaces the programmer’s reference with the actual code for the routine from the library file. after it has replaced all the references with actual code from the library, the linker then creates an executable binary file which can be executed by OS
Comments