Lecture 4 C Programming
Lecture 4 C Programming
In general, compiler is a computer program that reads a program written in one language, which is
called the source language, and translates it in to another language, which is called the target language.
Traditionally, source language was a high level language such as C++ and target language was a low
level language such as Assembly language.
However, there are compilers that can convert a source program written in Assembly language and
convert it to machine code or object code. Assemblers are such tools. So, both assemblers and
compilers ultimately produce code that can be directly executed on a machine.
Assembler Compiler
It translates the mnemonic codes such as PRN, It translates the high level language to assembly language.
ADD, and SUB etc. To machine language code.
The program, which executes using assembler, It takes time to execute a program, because it first
executes faster, because it directly converts the translates the source code into another compiler’s
source code in machine language. language and then using assembler converts it into
machine language.
كلية تكنولوجيا الصناعة والطاقة
4.3 Difference between: Compiler and Interpreter
Compiler Interpreter
Compiler translates the entire high level language The Interpreter translates the program written in high
program into the machine language program at once level language into machine language at the time of
before executing it. This optimizes the use of machine executing that program, instructions by instructions.
language instructions in the translated program. That is, it reads the first instruction written in the
Therefore normally compiled programs run faster program and converts that into equivalent machine
than Interpreted programs. The original high level language instructions. Then the CPU watches those
language program is called a s source program. The machine language instructions. After that, the
compiled program i.e. machine language program Interpreter reads and translates the next instruction
generated by the compiler after translation is called and so on.
object program.
Compiler Takes Entire program as input Interpreter Takes Single instruction as input.
Object code is permanently saved for future use. No object code is saved for future use.
Compiler Interpreter
Non time consuming translation method. Time consuming translation method كلية تكنولوجيا الصناعة والطاقة
Semantics Syntax
It is the logic or planning of the program. Semantics It is the way of writing the program in a particular
can be written in any of the following ways: programming language. Syntax changes from
1. Flowcharts. language to language.
2. Algorithms.
3. Pseudo codes.
4.4.1 FLOWCHART كلية تكنولوجيا الصناعة والطاقة
4.4.2 ALGORITHMS كلية تكنولوجيا الصناعة والطاقة
sum=num1+num2
Print sum
stop
كلية تكنولوجيا الصناعة والطاقة
In this week's lab, you’ll Apply
Apply the algorithm, Flowcharts, and Pseudo code to solve a simple problem, then write the code of
this problem using c programming language .
كلية تكنولوجيا الصناعة والطاقة
Thank
q
you