ITPP Principles of Procedural Programming
ITPP Principles of Procedural Programming
• Home for paying bills, shopping online, communicating, playing computer games,
etc.
• SmartPhones
• iPods
• Tablets
• Car navigation system (GPS)
1-3
1.1 Introduction
• Computers are designed to do any job that their programs tell them to do.
• A program is a set of instructions that a computer follows to perform a task.
For example: Microsoft Word and PowerPoint
• Programs are commonly referred to as software.
1-4
1.1 Introduction
• Programmersor Software Developers are the individuals
that create computer software.
• They have the training and skill to design, create,
and test computer programs.
1-5
1.2 Hardware and Software
Concept:
1-6
1.2 Hardware and Software
Hardware
1-9
1.2 Hardware and Software
Main Memory
• Considered the computer’s work area
• Computer stores the program that is running as well as the data
• Commonly known as the random-access memory (RAM)
• Data is quickly accessed
• RAM is a volatile type of memory
• Used for temporary storage
• RAM is erased when computer is turned off
1-10
1.2 Hardware and Software
• Read-Only Memory (ROM)
• A computer can read the contents of ROM, but it cannot change its
contents, or store additional data there.
• ROM is nonvolatile. It does not lose its contents, even when the
computer’s power is turned off.
• ROM is typically used to store programs that are important for the
system’s operation. For example, the computer’s startup program,
which is executed each time the computer is started.
1-11
1.2 Hardware and Software
Secondary Storage Devices
• Type of memory that can hold data for long periods of time.
• Programs and important data are stored in secondary storage
• Disk drive is a common type of secondary storage
• Solid-State drives are becoming increasingly popular
• Does not contain a disk. Instead, it stores data in solid-state memory
• No moving parts
• Operates faster than a traditional disk drive
1-12
1.2 Hardware and Software
Secondary Storage Devices
• USB drives are small devices that plug into the computer’s universal serial bus (USB) port
• It does not contain a disk
• The data is stored on flash memory
• Also known as memory sticks and flash drives
• Inexpensive, reliable, and small
• Optical devices (CD or DVDor Bluray)
• Data is encoded as a series of pits on the disc’s surface
• Uses laser to encode the data
• Holds large amounts of data
• Good medium for creating backups
1-13
1.2 Hardware and Software
Secondary Storage Devices
• Cloud Storage
• When you store data in the cloud, you are storing it on a remote server via the internet, or via a
company’s private network.
• You can access it from many different devices, and from any location where you have a network
connection.
• Can also be used to backup important data that is stored on a computer’s disk.
1-14
1.2 Hardware and Software
Input Devices
• Any data the computer collects from people and from other devices is called input.
• The hardware component that collects the data is called an input device.
• Common input devices are:
• Keyboard
• Mouse
• Touch screen
• Scanner
• Microphone
• Digital camera
Software
1-17
1.2 Hardware and Software
System Software
• Programs that control and manage the basic operations of a computer are referred to as
system software.
• Includes the following types:
• Operating System controls the internal operations of the computer’s hardware and manages
all of the devices connected to the computer.
• Utility Programs perform a specialized task that enhances the computer’s operation or
safeguards data. Examples disk defragmenter, antivirus software
• Software Developments Tools are programs that are used to create, modify, and test software.
1-18
1.2 Hardware and Software
Application Software
• Programs that people normally spend most of their time running on their computers
performing everyday tasks are referred to as application software.
• For example:
• Word processing
• Spreadsheet
• Database
• Presentation
1-19
1.3 How Computers Store Data
Concept:
1-20
1.3 How Computers Store Data
• A computer’s memory is divided into tiny storage locations known as bytes
• One byte represents one character
• A byte is divided into eight smaller storage locations known as bits (binary
digits)
• Bits are tiny electrical components that can hold either a positive or a negative
charge.
• A positive charge is similar to a switch in the on position
• A negative charge is similar to a switch in the off position
Figure 1- Think of a byte as eight switches
1-21
How a program works
• A computer’s CPU can only understand instructions that are written in
machine language. Because people find it difficult to write entire
programs in machine language other programming languages have been
invented.
• CPU is the most important part of the computer because it is the part that
runs the programs.
Functions of the CPU
• Reading a piece of data from main memory
• Adding two numbers
• Subtracting one number from another number
• Multiplying two numbers
• Dividing one number by another
• Moving one piece of data from one memory location to another
• Determining whether one value is equal to another value e.t.c.
CPU instructions
• A program is a list of instructions that cause the CPU to perform operations.
• Each instruction in a program is a command that tells the CPU to perform a specific
operation.
• Computers understand instructions that are written in machine language and machine
language is always in binary.
• A machine language instruction exists for each operation that a CPU is capable of
performing .
• The entire set of instructions that a CPU can perform is called the CPU’s instruction
set.
• There are many different types of processors and each processor
understands its own machine language.
• Each brand of processors has its own instruction set.(intel, motorolla)
• Programs are usually stored on a secondary storage device such as a hard
disk but it is copied to main memory every time you run the program.
Fetch-decode-execute cycle.
• When a CPU executes the instructions in a program it is engaged in a process that
is known as the fetch-decode-execute cycle.
• This cycle which consists of 3 steps is repeated for each instruction in the
program.
• Fetch-a program is a long sequence of machine language instruction. The first
step of the cycle is to fetch, or read the next instruction from memory into the
CPU.
• Decode: - The CPU decodes the instruction that was just fetched from memory to
determine which operation it should perform.
• Execute:- the last step in the cycle is to perform the operation.
From machine language to assembly
language
• A computer’s CPU only understands machine language. It is impractical
for people to write programs in machine language.
• Assemblers were written in the early days of computing as an alternative
to machine language.
• Assembly language uses short words known as mnemonics instead of
binary.
• E.g. the mnemonic add means to add numbers, mov means to move a
value to a location in memory.
From machine language to assembly language
• Assembly languages can not be executed by the CPU. The CPU only
understands machine language.
• An assembler converts assembly language program to a machine language
program.
Mov aex , z 10100001
Add aex, 2 Assembler 10111000
Mov y, aex 10011110
Assembly language
• Assembly language is a direct substitute for machine Languages and it
requires that you know a lot about the CPU. Examples are turbo pascal,
IBM PC DOS operating systems
• Assembly language requires that you write a lot of instructions even for
the simplest program.
• Because it is so close in nature to machine language it is known as low
level language.
High Level Languages
• Allows you to create powerful complex programs without knowing how the
CPU works and without writing large numbers of low level instructions.
• Most high level languages use words that are easy to understand.
• Example using Cobol to display the words hello world on the screen you
simply write the words Display “Hello world”.
• Doing the same thing in assembly language would require several instructions
and an intimate knowledge of how the computer video circuitry works.
• Examples of high level languages are Java, C, C++, Python, C#, Javascript
• Each high level language has its own set of words that the programmer must learn in
order to use the languages.
• Each key word has a specific meaning that cannot be used for any other purpose.
• In addition to keywords programming languages have operators that perform various
operations on data.
• Each programming language also has its own syntax(set of rules) that must be strictly
followed when writing a program.
• The syntax rules dictate how the keywords, operators and various punctuation
characters must be used.
• The individual instructions that you write in a high level language are called
statements.
Compilers and interpreters
• Programs written in high level language must also be translated to
machine language.
• A compiler or interpreter is used to make the translation.
• A compiler translates a high level program into a separate machine
language program. The machine language program can then be executed
anytime it is needed.
Compiler
High-level Machine
Language Program Language
Program
Display ”hello 10100001
Compiler 10111000
Earthling”
10011110
10100001
10111000 CPU
10011110
Interpreter
• An interpreter is a program that both translates and executes instructions
in a high level language program.
• As the interpreter reads each individual instruction in the program, it
converts it to a machine language instruction and then immediately
executes it. Machine
High level
language
program
instruction
Display “Hello 10100001
Interpreter CPU
World”
• The programs that are compiled generally execute faster than programs
that are interpreted because a compiled program is already translated
entirely to machine language when it is executed.
• The statements that a programmer writes in high level language are called
source code or simply code.
• A code that has syntax error cant be translated.
• A syntax error is a mistake such as a misspelt word, omission of a
punctuation character e.t.c.
Integrated Development Environment
• You can use a simple text editor such as Notepad to write a program, most programmers
use specialised software packages called Integrated Development Environments.
• Most IDEs combine the following programs into one software package:
• A text editor with specialised features for writing statements in a high level programming
language
• A compiler or interpreter
• Useful tools for testing programs and locating errors.
• Examples of IDEs include Microsoft Visual Studio(C++, VB, C#), Netbeans,
Eclipse
Types of Software
• We have 2 categories of software:
• System software
• Application software
System Software
• These are programs that manage and control the basic operations of a computer. System
software includes:
• Operating Systems:- most fundamental set of programs on a computer. It controls the
internal operations of the computer’s hardware, manages all the devices connected to the
computer, allows data to be saved to and retrieved from devices and allows other
programs to run on the computer.
• Utility programs:- these perform specialised tasks that enhance the computer’s operation
or safeguards data. Virus scanners, file compression programs and data backup programs
are examples of utilities.
• Software development tools-: these are the programs that programmers
use to create, modify and test software. Assemblers, compilers and
interpreters fall into this category.
Application Software.
• Programs that make a computer useful for everyday tasks are known as
application software.
• People normally spend most of their time running these programs.
• Game programs, spreadsheets, word processors, web browsers, e-mail
programs e.t.c.
Questions???