Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

CSE 1101

Structured Programming
Nazirul Hasan
Lecturer
Dept. of CSE
KUET
What is programming?
• Series of instructions to a computer to accomplish a task
• Instructions must be written in a way the computer can understand
• Programming languages are used to write programs

January 3, 2023 2
Computer Languages
Human languages are known as natural languages.
Unfortunately, computers can not understand natural
languages, as a result we must communicate with
computers using computer languages. These languages
are;
• High Level Languages
• Low Level Languages (Assembly Languages)
• Machine Language

January 3, 2023 3
Machine language
Machine code or machine language is a
system of instructions and data executed
directly by a computer's CPU, The lowest-level
programming language that only be
understood by computers.

Computer language that is directly executable


by a computer without the need for
translation by a compiler or an assembler.

January 3, 2023 4
Machine Language
The native language of the computer,
The set of symbolic instructions in binary that is used to
represent operations and data in a machine called
machine code
Machine Language: “0110101100101000”
machine language is a collection of binary digits or bits
that the computer reads and interprets.

Machine language is the only language a computer


understands, It is almost impossible for humans to use
because they consist entirely of numbers.

January 3, 2023 5
Low Level Language
A computer low level language that deals with
hardware registers by name known as assembly
language.

Assembly language is the best example of low level


language, this is in between machine language and
high-level language.

January 3, 2023 6
Low Level Language(Assembly Language)
It uses mnemonic codes (short forms) for instructions
and allows the programmer to introduce names for
blocks of memory that hold data.
Assembly language is designed to be easily translated into
machine language.

January 3, 2023 7
High Level Language

The high-level languages are much closer to human


language.
A programming language such as FORTRAN or Pascal
that enables to write programs which is understandable
to programmer (Human) and can perform any sort of
task, such languages are considered high-level because
they are closer to human languages.

January 3, 2023 8
Examples:

C#
FORTRAN
PASCAL
PROLOG
JAVA
.NET
C
C++

January 3, 2023 9
Program code converters

• INTERPRETER
• COMPILER
• ASSEMBLER

January 3, 2023 10
Interpreter

Interpreter converts a source code , usually on a


step-by-step, line-by-line and unit-by-unit basis into
machine code.

Example: Python, ruby

January 3, 2023 11
Compiler and Assembler

Compiler is a program that compile source code into


executable instructions that a computer can understand.
Example: C compiler

Assembler normally converts assembly language’s source


code into machine language.
Example: GNU assembler

January 3, 2023 12
Types of programming
• Structured Programming (C)
• Object-Oriented Programming (C++)
• Logic/Declarative Programming (Prolog)
• Functional/Applicative Programming (Lisp)

January 3, 2023 13
Structured Programming

• A disciplined approach to programming


• Top-down design

January 3, 2023 14
Top Down Design
• A program is divided into a main module and its related modules. Each
module is in turn divided into sub-modules until the resulting modules are
understood without further division.

January 3, 2023 15
Why do structured programming?

•It's easier to understand code written


using structured programming
•Easier to test and debug code
•Easier to modify and maintain code
•Easier to work with other people to write
large programs

January 3, 2023 16
4 Control Structures

• Sequence
• Selection
• Iteration
• Module

January 3, 2023 17
SEQUENCE

Statement 1 Statement 2 Statement 3 ...

January 3, 2023 18
SELECTION(branch)

IF Condition THEN Statement1 ELSE Statement2

Statements1
Statement
Condition ...
Statements2

January 3, 2023 19
LOOP(repetition)

WHILE Condition DO Statement1

False
...
Condition

Body

January 3, 2023 20
SUBPROGRAM(function)

SUBPROGRAM1 ...

SUBPROGRAM1
a meaningful collection
of SEQUENCES,
SELECTIONS, LOOPS

January 3, 2023 21
Module Flow of control

January 3, 2023 22
The Four Stages of Compiling a C Program

• Preprocessing
• Compilation
• Assembly
• Linking

January 3, 2023 23
Preprocessing

This is the first phase through which source code


is passed. This phase include:
• Removal of Comments
• Expansion of Macros
• Expansion of the included files.

January 3, 2023 24
Preprocessing

January 3, 2023 25
Preprocessing

After preprocessing, filename.i is produced


January 3, 2023 26
Compilation

In this stage, the preprocessed


code is translated to assembly
instructions

After compiling, filename.s is produced

January 3, 2023 27
Assembly
• During the assembly stage, an assembler is used to translate the
assembly instructions to machine code, or object code.

After assembling, filename.o is produced

January 3, 2023 28
Linking

• The linker will add the object code for the built-in function and some
extra work is done here.

After linking, filename.exe is produced

January 3, 2023 29
References

• Web

January 3, 2023 30

You might also like