Lesson 1
Lesson 1
Lesson 1
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.