Structured Programming Theory L-01
Structured Programming Theory L-01
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.
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.
January 3, 2023 5
Low Level Language
A computer low level language that deals with
hardware registers by name known as assembly
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
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
January 3, 2023 11
Compiler and 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
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?
January 3, 2023 16
4 Control Structures
• Sequence
• Selection
• Iteration
• Module
January 3, 2023 17
SEQUENCE
January 3, 2023 18
SELECTION(branch)
Statements1
Statement
Condition ...
Statements2
January 3, 2023 19
LOOP(repetition)
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
January 3, 2023 24
Preprocessing
January 3, 2023 25
Preprocessing
January 3, 2023 27
Assembly
• During the assembly stage, an assembler is used to translate the
assembly instructions to machine code, or object code.
January 3, 2023 28
Linking
• The linker will add the object code for the built-in function and some
extra work is done here.
January 3, 2023 29
References
• Web
January 3, 2023 30