The four stages of compilation

KS3 Computer Science

11-14 Years Old

48 modules covering EVERY Computer Science topic needed for KS3 level.

GCSE Computer Science

14-16 Years Old

45 modules covering EVERY Computer Science topic needed for GCSE level.

A-Level Computer Science

16-18 Years Old

66 modules covering EVERY Computer Science topic needed for A-Level.

KS3 Programming Languages (14-16 years)

  • An editable PowerPoint lesson presentation
  • Editable revision handouts
  • A glossary which covers the key terminologies of the module
  • Topic mindmaps for visualising the key concepts
  • Printable flashcards to help students engage active recall and confidence-based repetition
  • A quiz with accompanying answer key to test knowledge and understanding of the module

A-Level Basic programming constructs (16-18 years)

  • An editable PowerPoint lesson presentation
  • Editable revision handouts
  • A glossary which covers the key terminologies of the module
  • Topic mindmaps for visualising the key concepts
  • Printable flashcards to help students engage active recall and confidence-based repetition
  • A quiz with accompanying answer key to test knowledge and understanding of the module


Introduction to the four stages of compilation: Compilation is the way toward changing over source code into object code. This is finished with the assistance of the compiler. The compiler checks the source code for linguistic or basic mistakes, and if there are no blunders in the source code, it creates the objective code.

The four stages of compilation Image 1

The c gathering measure changes over the information source code into object code or machine code. The fabricate cycle can be separated into four stages: preprocessing, accumulation, gathering and connecting.

The preprocessor main function is that it takes the code and removes all the comments from the desired source program The preprocessing program receives and interprets the preprocessing program instructions. For example, for <stdio.h>, the instruction can be used programmatically, and the preprocessor will interpret the instruction and replace it with the content of the “stdio.h” file.

These are the stages that the program goes through before it is converted into a viable format.

  • First one is Preprocessor
  • Second one is Compiler
  • Third is preprocessor Assembler
  • Fourth one is preprocessor Linker
Illustration of the four stages of compilation.


The source code is written in a content tool, and the expansion of the source document is “.c”. The source code is first passed to the preprocessor, and afterward the preprocessor executes this code. In the wake of separating the code, pass the extended code to the compiler.

The primary stage of aggregation is known preprocessing. At this phase, lines starting with the # characters are decoded by the preprocessor as preprocessor orders. These orders structure a basic whole scale language with its possessive grammar and semantics. This language is used to decrease source code cycle by including documents, characterizing macros, and giving the capacity to restrictively skip code.

The preprocessor performs initial processing before interpreting the command. This includes connecting continuation lines and deleting comments from the source program.

Working of preprocessor

Preprocessors are system software (computer programs designed to run on computer hardware and applications). Performed high-level language preprocessing (HLL). Initial processing is the first step in the language processing system. Language processing systems convert high-level languages into machine-level languages or absolute machine codes (for example, in a form that the machine can understand).

Preprocessor directives do not know about C scoping rules. Preprocessor directives, such as #define, take effect as soon as they are seen and do not take effect until the end of the containing file. The structure of the program block does not matter.

Main Function of Preprocessor

1. Delete comment

The comment is only used to make people understand the password. Therefore, it is obvious that the machine does not need them. Then, delete all the previously valid content, because they do not need to work and will not work.

How to view deleted annotated documents in Linux):

2. File input

Contains all the library documents needed for our code. In high level language, we write #iostream, which is basically the head of the preprocessor that gives information to you to enter the main theme of the specified library document. For example, #iostream will tell us the pre-worker to involve all the content in the library file.

You can also write using a pair of suggestions – #iostream “stdio.h”

Note: If the file name is in square brackets, it will be searched in the compiler with standard input paths. If the file name is bound in double quotes (“”), the search path is expanded by entering the current source index.

3. Extending macros

Macros are also known as the little functions that do not carry a workload. If we write a function (which has a little definition) that wants to be called recursive, we must give preference to macros over functions.

Thus, the definition of this macro is carried out by the pre-worker.


The program enlarged by the preprocessor will proceed to the compiler. The compiler alters this program into an assembly program. In addition, the C compiler can convert the preprocessed code into assembly code. The second phase of the compiler is inconsistently called compilation. In the phase, the preprocessed program will be converted into specific assembly commands for the target processor commands. These constitute the middle language that humans can read.

The extent of this step allows you to include inline assembly commands in your C code and use multiple assembly programs. Some compilers also support the use of built-in assemblers. In this case, the machine program is directly caused during the compilation phase, thereby keeping away from the overhead of middle assembly commands and calling the assembly program.

More elevated level programming dialects typically show up considering a sort of interpretation: either planned as ordered language or deciphered language. Notwithstanding, by and by there is once in a while anything about a language that expects it to be only assembled or only deciphered, despite the fact that it is conceivable to plan dialects that depend on pre understanding at runtime. The arrangement generally mirrors the much famous or far and wide usage of a language — for example, BASIC is once in a while called a deciphered language, and Can incorporated one, regardless of the presence of BASIC compilers and C translators.

Understanding doesn’t supplant accumulation totally. It just conceals it from the client and makes it continuous. Despite the fact that a mediator would itself be able to be deciphered, a straightforwardly executed program is required some place at the base of the stack

When we use compiler

A machine realizes only binary language and performs binary language program instructions. In no other type can it execute a single instruction given. So we need to send

the machine instructions into binary languages. Means that we have to write computer codes/programs whole in the binary language (0s and 1s sequence).

But think about how unwieldy programming would have been for a while, if we had been, if we have to write an order of 0s and 1s for every program?

Writing sophisticated software would have been a nightmare. Man is better at delivering commands in English, while the computers only process binary language. Thus, an interpreter compiler was invented to accomplish the task. Thus, a translator was required to translate the

machine instructions provided in English into binary language.

Characteristics of Compiler

Besides translating source programs from high level language into low level language, the compiler also has other obligations. It operates below operations after scanning source program written in high level language

  • Execute source code pre-processing. Gather all of the files needed to compile the source code.
  • The whole source program is parsed. Any syntax errors in the source program are tested.
  • Perform a detailed review of the source programs syntax. To grasp the source program structure and semantics.
  • Optionally, to boost performance, it converts the source program into a middle program known as an object program.
  • Translates the code of the object into the binary language known as workable.

Comparison Between Compiler and Interpreter

Compiler filters the entire program in one go.Interprets program each announcement in turn.
As it examines the code in one go, the blunders (assuming any) appear toward the end together.Thinking of it as sweeps code each line in turn, blunders are indicated line by line.
As it examines the code in one go, the blunders (assuming any) appear toward the end together.Because of mediators being delayed in executing the article code, it is favored less.
It changes over the guidelines into orderly code.It doesn’t change over the guidelines rather it legitimately takes a shot at source language.
C,C# and so forth.Python Perl, SNOBOL and so on.


Assembly program converts assembly program into object program. The name of the object file produced by the assembler is the same as the name of the source file. The addition/extension of DOS object files is “.obj”, and the extension of UNIX is “o”. If the source file is named “hello’s”, the target file will be named “hello.obj”.

At this stage, the assembler is operating to convert assembly commands into object programs. The output consists of the real commands executed by the target processor.

Running the above instruction will have built a file that is named hello word. o, which contains the object program of the code. The content of the file is in binary design.

Basic Function of Assembler

The basic function of assembler is as follows:

  • interpreting mnemonic language programs to its equivalent object code
  • assigning machine delivers to emblematic names

The plan of constructing agent can be performed by:

  • Scanning
  • Parsing
  • Making the image table
  • Settling the forward reference
  • Changing over into the machine language

The planning of constructing agent in another words

  • Convert mental aide opcodes to identical machine language
  • Convert representative operands to approach machine addresses
  • Decide the proper guidance configuration to change over the information steady on the inner machine
  • Compose program items and establishment records

Therefore, in the assembly design, SIC / XE machine. You are required to define the algorithm and different data structures used. Installation procedure according to the above requirements Manages installer instructions. These instructions do not generate object code, and the installer performs certain operations.

Working of Assembler

Constructing agents are like compilers in that they produce executable code. In any case, constructing agents is easier in light of the fact that they just believe low-level code (low-level computing build) into a machine program. Since every low-level computing build is intended for a particular processor, the gathering of the program is finished by a straightforward balanced planning from get together code to machine code. Then again, the compiler must change over broad elevated level source code into processor-explicit machine code.

Most projects are written in elevated level programming dialects and are aggregated legitimately to machine code utilizing a compiler. In any case, now and again, gathering code might be utilized to modify works and guarantee they act with a certain goal in mind. Accordingly, IDEs regularly incorporate constructing agents so they can fabricate programs from both high and low-level dialects.

 Comparison Between Assembler and Interpreter

It changes over low-level language to the machine language.It changes over significant level language to the machine language.
The program for an Assembler is composed for specific equipment.The program for an Interpreter is composed for a specific language.
It is balanced for example one guidance means just a single guidanceIt is one to numerous for example one guidance means numerous guidance.
It deciphers the whole program before running.It interprets program directions line by line.
Blunders are shown before the program is running.Mistakes are shown for the each deciphered guidance (assuming any).
It is utilized as just one opportunity to make an executable document.It is utilized each time when the program is running.
Necessity of memory is less.Prerequisite of memory is more.
Programming language that it converts is Assembly language.Programming languages that it converts are PHP, Python, Perl, Ruby.


Essentially, all projects written in C use library capacities. The capacity of this library is preconfigured, and the item code of this library report is put away with the augmentation “.lib” (or “. a”). The principle capacity of the fastener is to join the article code from the report library with the program object code.

In some cases, this happens when our program alludes to a capacity characterized in another archive; Therefore, the latch assumes a significant part in this work. Join the article code from these reports to our program. Thus, the undertaking of the cover is to connect the program object code with the archive library object code and different reports. The yield connector is an executable report. The executable report name is equivalent to the source record name, however has an alternate augmentation.

In DOS, the executable record expansion is “.exe”, on UNIX, the executable document can be named “a.out”. For instance, on the off chance that we utilize the printf () work in a program, the connector will add the related code to the yield report.

The item program created in the gathering phase is constructed out of machine language instruction that the processor can see, however some portion of the code is absent or lost. To assemble an executable code, you should migrate the primary parts and fill in the missing parts. This cycle is known.

The linker places the objective program fragment with the aim that specific capacities can effectively call different capacities. Moreover, include a segment containing depictions of library capacities utilized by the program. To “Hi World!” For the program, the linker includes the item code for the business work.

An organizer is a program on a framework that can assist connect with protesting modules to a solitary article report. Experience the end cycle. The connector is likewise called the connection supervisor. Bundling is the way toward gathering and putting away code and information portions in a record. The connector additionally associates certain modules to the framework library. It accepts the article module as contribution from the gatherer and structures an archive that can be executed as yield from the loader.

At the point when source code is changed over to machine code, the association is made during accumulation; When the bootloader loads the program into memory, an association is built up during the download. The association is made in the last phase of programming.

Source code – > compiler – > Assembler – > object code – > linker – > executable document – > loader

 Sorts of Linking

It is executed during the aggregation of source code. Connecting is executing before execution in static connecting. It takes an assortment of moveable item records and order line contention and produces a completely connected article document that can be stacked and run.

Main Task of Linker

Symbol Resolution

 It relates every image recommendation with precisely one image definition. Every image has a pre planned task.


It moves code and information and adjusts image recommendation to the moved memory area.

The linker duplicates all library schedules utilized in the code into a compilable picture. Accordingly, it requires more memory space. As it doesn’t need the existence of library on the framework when it is running. thus, it is quicker and more convenient. No disappointment possibility and less blunder possibility.

As the compiler has no data on the design of items in the last yield, it can’t exploit smaller or more productive directions that can place a prerequisite on the location of another article. For instance, a hop guidance can recommend a flat out location or a balance from the current area, and the balance could be communicated with various lengths relying upon the separation to the objective. By first creating the most moderate guidance (ordinarily the biggest family member or total variation, contingent upon stage) and including unwinding indications, it is conceivable to substitute shorter or more productive directions during the last connection. Concerning hop enhancements this is additionally called programmed hop sizing.

This progression can be executed simply after completely input things have been perused and doled out impermanent locations; the linker unwinding passes accordingly redistribute addresses, which may thus permit more possible composures to happen. As a rule, the subbed arrangements are smaller, which permits this cycle to consistently merge on the best arrangement provided a stable request of articles; if this isn’t the situation, composure can struggle, and the linker requires to gauge the upsides of either alternative.

Types of Linker

Dynamic Linking

Dynamic interfacing is executed during the run time. This association is developed by placing the name of a shareable library in the executable picture. There are more chances of mix-up and frustration prospects. It requires less memory space as various tasks can share a lone copy of the library.

Here we can perform code sharing. It suggests we are using a proportionate thing for different events in the program. Instead of interfacing the same thing again and again into the library, each module confers information about a thing to another module having the same article. The shared library required in the interfacing is taken care of in virtual memory to save RAM. In this interfacing we can moreover move the code for the smooth running of code yet all the code isn’t relocatable. It fixes the area at run time.

Linkage editor

In IBM System/360 concentrated PC conditions, for example, OS/360, including z/OS for the z/Architecture consolidated laborers, such a program is known as a linkage supervisor. As the name suggests a linkage boss has the extra furthest reaches of permitting the turn of events, substitution, and also scratch-off of individual program zones.

Working structures, for example, OS/360 have plan for executable weight modules containing productive information about the segment parts of a program, so an individual program an area can be uprooted, and different pieces of the program empowered so relocatable regions and different references can be reconsidered by the linkage manager, as a segment of the cycle.

A tiny smidgen of room in this is it permits a program to be kept up without keeping the entire of the halfway thing documents, or without having to re-combine program sections that haven’t changed. It moreover allows program updates to be dispersed as pitiful records (from the outset card decks), containing just the thing module to be uprooted.

In such frameworks, object code is in the structure and blueprint of 80-byte punched-card pictures, so updates can be brought into a structure utilizing that medium. In later appearances of OS/360 and in following structures, load-modules contain extra information about understanding of segments modules, to make a perceptible record of updates. It likewise permits one to join, change, or shed an overlay structure from a once related difficulty module.

The enunciation “linkage boss” ought not be seen as suggesting that the program works in a client sharp mode like a substance gadget. It is typical for pack mode execution, with the altering orders being given by the client in dynamically filtered through records, for example, punched cards, DASD, or appealing tape, and tapes were regularly utilized during the fundamental establishment of the OS.

Linkage modifying (IBM wording) or solidifying or assortment (ICL plan) recommends the linkage editorial manager or consolidator’s display of joining the different pieces into a relocatable equivalent, while the stacking and development into an inside and out joined at the objective territory is normally observed as a substitute turn of events.


  1. PC Mag Staff (28 February 2019). “Encyclopedia: Definition of Compiler”. Retrieved 28 February 2017.
  2. Fraser, Christopher W.; Hanson, David R. (April 1982). “A Machine Independent Linker”. Software: Practice and Experience. John Wiley & Sons Ltd. 12 (4): 351–366. doi:10.1002/spe.4380120407. ISSN 1097-024X.
  3. Christensson, P. (2014, September 5). Assembler Definition. Retrieved 2020, Sep 20, from