Compiling and Running A Program: Introduction To A Programming Language

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Compiling and Running a Program

INTRODUCTION TO A PROGRAMMING LANGUAGE


Target

By the end of this learning guide module, the students should be able
to:
1. Understand the mechanism on how computer programs are being
compiled;
2. Build source codes designed for programming;
3. Compile and execute a C++ program.
Review
We have learned from the last module the basic components of a
computer program.

We have identified how each component in the structure works in


the entire program. For today we will learn how to compile and run
a program.
Let us recall that computers can only
understand Machine Language. Machine
languages are composed of just 0s and 1s.

The question now is, how does our computer


program, which is of course alpha-numeric
characters, be understood and run by a
computer?

Will it be something like this?

With today’s lesson, we will try to


uncover the mystery behind this. We
will try to understand how our code is
being processed and executed

Image source: https://www.facebook.com/ProgrammerLang/photos/a.467124023782044/881234095704366/


We have learned from previous topics
about machine languages, low level
languages and high-level languages.

It has been discussed that computers can


only understand machine language and
now we are ready to understand how our
simple code is translated into machine
language.
HIGH LEVEL LANGUAGE

A high-level language is any programming language that enables


development of a program in a much more user-friendly programming
context and is generally independent of the computer's hardware
architecture.
ASSEMBLY LANGUAGE
Assembly language is a type of programming language that communicates with
the hardware of a computer. 

The assembly language is the bridge between the manufacturer's machine


language for the hardware to the more complex programming languages used in
software, which is typically easier for a human to read and manipulate.

Here is an example of assembly language. The below code signals to a processor in binary
code to add the numbers 3 and 4:

1: MOV eax, 3
MOV ebx, 4
ADD eax, ebx, ecx
MACHINE LANGUAGE
Sometimes referred to as machine code or object code, machine
language is a collection of binary digits or bits that the computer reads
and interprets. Machine language is the only language a computer is
capable of understanding.

The exact machine language for a program or action can differ by 
operating system. The specific operating system dictates how a compiler
writes a program or action into machine language.
COMPUTER HARDWARE

•Computer Hardware is the physical


components that a computer system requires
to function. It encompasses everything with a
circuit board that operates within a PC or
laptop; including the motherboard, graphics
card, CPU (Central Processing Unit), ventilation
fans, webcam, power supply, and so on.
The figure shows how a C++ program is being processed from a code to an executed program.
Step 1
We create our program on a text editor (or IDE) with the right syntax. Our
program written on this editor is what we call a source code. Our source code is
written using the high-level programming language. The file then will be saved
with the .cpp file extension.

As a programmer, you must learn, understand, and master the rules of the
programming language to create source programs.
Step 2
The program will then look for the #include statement or what we
call the preprocessor directive.

It will include any library indicated by the #include object.


Step 3
After processing preprocessor directives, the next step is to verify that the program
obeys the rules of the programming language—that is, the program is syntactically
correct—and translate the program into the equivalent machine language.

The compiler checks the source program for syntax errors and, if no error is found,
translates the program into the equivalent machine language of a high-level
language – object program.
Step 4
Programs written on a high-level language are developed in the integrated development
environment (IDE). The IDE contains necessary code(program) such as displaying results and
multiple mathematical functions that programmers can use, rather than making their own code.

Once the program is developed and successfully compiled, you must still bring the code for the
resources used from the IDE into your program to produce a final program that the computer
can execute.

This prewritten code (program) resides in a place called the library. A program called a linker
combines the object program with other programs in the library and is used in the program to
create the executable code.
Step 5
The program is loaded to the main memory for execution. The loader will be
responsible for doing this task.
Step 6
Finally, the program is executed.
What you have learned today is how to run and compile a computer
program.

 We create our source codes using a workspace in the Ide or a text editor.
 The preprocessor directive will include all the necessary library in the
program.
 The compiler checks the source program for syntax errors and, if no error
is found, translates the program into an object program.
 The linker combines the object program with other programs in the
library and is used in the program to create the executable code.
 Once it becomes an executable code, it can be run.

We have also discussed o how to create and run a program using the IDE –
DevC++/Codeblocks. We have discussed how to create a program and all the
necessary steps to run the program.

You might also like