Lesson 1

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

INTRODUCTION TO BASIC

COMPUTER PROGRAMMING
Lecture 1,2,3
Computer Systems Unit
COMPUTER PROGRAMMING
COMPUTER PROGRAMMING
Computer program is a sequence of instructions
written to perform specified task after execution by
the computer in its central processing unit.
A sequence is the order in which the instructions in a
program are carried out.
Instructions are commands directing the computer
central processing unit how to handle certain tasks.
Examples of instructions
(commands)
Copy, Print, Delete, Over
with in a computer
write, Rename, Add, Subtract, Divide
Computation Task
Y =3+2
Y = (3 – 1 ) / 3
This is a computational task with an instruction “Add
two numbers 3 and 2 and assign the results to a
variable Y”
Using BODMAS we can drive the following commands;
BRACKETS, ADD, ANSWER / PRINT
Computer program
Example
Step 1: Y = 3 +2
Step 2: Z = Y - 2
Step 3: X = Z ÷ 2
Step 4: T = ADD(Y,X,Z)
Step 5: PRINT (Y,Z,X,T)
Step 6 : STOP
Computer Instruction sets
The sequence of steps attempting the task each
containing statements can be written by the computer
programmer
The set of instructions meant to complete a particular
tasks is called a computer program
The text editor suitable to a specific programming
language is called a programming environment.
Library functions refers to the pre defined functions
within a programming environment
Source code – working functions together with the
programming environment in any text editor in a human
readable form.
Compilation of the source code by the computer
central processing unit generates an executable
program – Machine code
Instruction set- The collection of numerical codes
which directs the computer to perform such simple
operations.
An illustration of computer CPU
Executable program
Types of computer Instructions
1) Data Transfer – move data within the processor,
between the computer and the computer internal
memory or other external devices.
2) Arithmetic operations – instructs the computer to
carry out arithmetic operations such as addition,
subtraction, multiplication, division, increment,
decrement, comparison and logical operations e.g
AND, OR, NOT, EXECLUSIVE
3) Shift Operations - move data to the left or right with
in the register of memory location
4) Transfer of control - directs the computer to skip one
or more instructions or repent previously encounter
instructions.
The evolution of programming
languages
A low-level programming language is a programming
language that provides little or no abstraction from a
computer's instruction set architecture—commands
or functions in the language map closely to processor
instructions.
Types of low-level language are:
1) Machine code
2) Assembly language
Machine code
The instruction sets are represented by binary codes
which can be decoded by the control unit, resulting
into the computer carrying on the appropriate
operations.
001
0010
Assembly language
The function codes are replaced by mnemonics. A
mnemonic is a word or a set of letters which is easy to
remember and which can be used by the programmer
to represent a function code
Addresses and operands can be replaced by labels or
names inverted by the programmer.
Each instruction of an assembly language translates
into one machine code instruction.
Examples;
ADD, STORE, HLT, LDR
Assembly language Vs Machine code
Assembly language
Advantages of Machine code over
assembly
Machine language makes fast and efficient use of the
computer.
It requires no translator to translate the code.

Disadvantages of a Machine code


1. All operation codes have to be remembered
2. All memory addresses have to be remembered.
Advantages of Assembly languages

1) It allows complex jobs to run in a simpler way.


2) It is memory efficient, as it requires less memory.
3) It is faster in speed, as its execution time is less.
4) It is mainly hardware-oriented.
5) It requires less instruction to get the result.
6) It is used for critical jobs.
Disadvantage of Assembly
language
1) Takes a lot of time to type codes per code
2) Its operations can easily be a target for bugs.
3) Its machine dependent thus user will not be able
to get any output due to its architecture.
High level languages
 Is based on the problem being solved than the
machine being used.
 Each instruction of a high level program translate
into a number of machine code instructions.
 High level language can specify the evaluation of a
complex arithmetic expression requiring many
machine code instructions.
 High level languages can be categorised according
to the number of generations , from the first to the
latest or fifth generation.
First Generation
Based on the architecture of the current computers
Closely related to the instructions set of machines such as
IBM 704
Data structures were similarly based on the internal
representation used for numbers and characters.
Punched cards were the main input medium for the
program.
Example: FOTRAN
FORTRAN, in full Formula Translation, computer
programming language created in 1957 by John Backus
that shortened the process of programming and made
computer programming more accessible.
2nd Generation
Elaborated on the structure of the 1st generation
languages
The overall structure is re -organised to aid program
design.
Structured programming by the introduction of more
structured control structures
The syntax of the language become more flexible
allowing statements to be expressed in a free form
Example: ALGOL – 60
3rd Generation computers
User defined data structures become available
Allowed more application oriented approach to
programming adopted.
Language become more independent of the
computer hardware
Control structures were modified to make simpler
and more efficient than those of the previous
generation
Example : PASCAL
4th Generation
These are languages that consist of statements that are
similar to statements in the human language. These are
used mainly in database programming and scripting.
Reduced the work of the user and increased the work of
the computer
They are more concise than previous generations
The syntax is usually closer to natural languages
They are user friendly.
Example: Perl, Python, Ruby, SQL,
MatLab(MatrixLaboratory).
5th Generation
A fifth-generation programming language is any
programming language based on problem-solving
using constraints given to the program, rather than
using an algorithm written by a programmer.
Facilitate implementation on an alternative computer
Architecture
Allow programs to be implemented using parallel
processing techniques, object – oriented
Example: Perl, Python, Ruby, SQL,
MatLab(MatrixLaboratory).
Compilers Vs Interpreter
Is a program which translates a complete high level
program into a machine code program
An interpreter is a program which interprets a high level
program one line at a time while it is being run.
An interpreter may not produce a machine code
translation for each line , but instead executes machine
code routines corresponding to the high level instruction
in the line.
For each language compiler, an interpreter has to be
written for every different type of a computer the
language is used on.
Compilers Vs Interpreter
Compilers Vs Interpreter
Functions of a compiler
1) Translate or interpret source code written in a
high level language
2) Detect errors in the program and print error
messages
3) Organise storage of variables used for the
program
4) Link the program with any other software it uses
Advantages of a compiler
1) Once the program is compiled it can be used
again and again without any further translation
2) Each line of code has to be translated only once
during compilation
Advantages of an interpreter over a
compiler;
1) The program can be changed easily if a run is
unsatisfactory
2) The version of the program which is in the store is
relatively short
How an Interpreter works? PHP,
CSS, HTML scripts
From Code to a Software program
Qualities of a good software
program
1) Reliability – how often are results of the program accurate
2) Actual correctness of algorithms.
3) Minimal programming mistakes like logical errors – division by
zero.
4) Usability – Easier with which the person can use the program for
its intended purpose.
5) Portability - range of computer hardware and operating system
platforms on which the source code of the program can be
compiled / interpreted.
6) Maintainability – Easier with which the program can be modified
in future.
7) Efficiency / performance – how human time and memory space
needed to finish a computational task in comparison to similar
programs.
Software programs Icons
Recap – Types of Software programs
The End
Thanks for listening

You might also like