You are on page 1of 32

Done By: Gideon Ramcharan

Module 1
Objective one: State the purpose of the main components of a computer system

-Input and output devices (peripherals)

Input devices are used to send signals/data to the system from the outside world while output
devices are used to receive information/data from the system.

Input devices: Keyboard, Mouse, Light (optical) Pen, Barcode Scanner, Joystick, Gamepad,
Webcam, and Scanner.

Output devices: Monitor, Printer, Headphones, and Speakers.

Considered Both: Camera, Headset, Touch screen, Flash Stick and Modem

Port Connectivity- This is the ability to connect a device to your computer.

A port serves as an interface between the computer and other computers or peripheral devices.

Specialized Devices

Large or Braille keyboards

Voice Recognition

Text to Speech

-Memory Types

RAM- (main memory) stands for Random Access Memory.

It is used to store data temporarily.

It stores data/ programs while being used by the CPU.

The data stored in the RAM can be accessed much faster than data stored in secondary
storage devices.
Done By: Gideon Ramcharan
It is volatile/dynamic which means if the computer switches off; the RAM loses all the
information stored on it.

ROM- Stands for Read Only Memory.

It stores data and programs written permanently by the manufacturers.

It holds data and programs which are require for the computer to start.

It is non-volatile.

PROM- Stands for programmable Read Only Memory.

It can have programs or data written to it after manufacturing but cannot be re-written.

EPROM- Stands for Erasable Programmable Read Only Memory.

It can be erased after data/programs are stored on it by the use of ultra violet light then
written to again.

EEPROM- Stands for Erasable Electronic Programmable Read Only Memory

It can be programmed and erased in-circuit, by applying special programming signals


(high voltages), without removing it from the computer.

-Memory Features

Speed- The rate at which data can be read or written to memory

Size- The amount of data that can be written to the memory

Word Size- The number of bits that a CPU can process at one time

Volatility- Volatile memory is computer memory that requires power to maintain information
stored on it while Non-Volatile memory does not require power to maintain information stored
on it.
Done By: Gideon Ramcharan

-Storage Devices

Capacity: The amount of data that can be stored on a storage device.

Access Speed: The rate at which data can be retrieved from storage devices

Types of Access (access methods)-

Serial Access: records are accessed in the order in which they have been stored (Magnetic Tape Drives)

Sequential Access: records are accessed in ascending or descending key sequence.

Direct Access: records are accessed by simply selecting file name from options.

-Security

Surge Protector: Protects against spikes in electricity being passed.

Voltage Regulators: Provides a constant voltage rate when electricity is being passed.

Uninterruptible Power Supplies (UPS): Used to prevent against damage to hardware in the event
of a power loss by switching to battery backup when the power shuts down.

-Types of computers

Supercomputer:

-The fastest type of computer

-Very expensive

-For special applications that require a lot of mathematical calculations such as animated
graphics, fluid dynamic calculations, nuclear research, and weather forecasting.

-Can execute a single program faster than a mainframe

Mainframe:

-Very Large and expensive (smaller than supercomputers)

-Capable of supporting hundreds or thousands of users simultaneously

-Capable of running many programs simultaneously


Done By: Gideon Ramcharan
-Supports many terminals and peripherals

-Used in banks, airlines and utility companies

Microcomputer:

-Small

-Inexpensive

-Has a microprocessor as its central processing unit.

Laptop:

-Portable personal computer (small, lightweight)

-Inexpensive

-Usually battery powered

PDA:

-Known as a palmtop computer or personal data assistant

-mobile device

-combines computing, telephone, fax, internet and networking features

-Usually uses a stylus


Done By: Gideon Ramcharan

MODULE 2
Problem Solving- The process of working through details of a problem to reach a solution,
Problem solving may include mathematical or systematic operations and can be a measurement
of an individual's critical thinking skills

Steps for problem solving-

1) Define the Problem

2) Analyze the Problem

3) Identify and Evaluate possible solutions

4) Select and justify the optimal solutions

5) Implement it

6) Review it

Algorithm- a sequence of steps which provide a solution to a problem

It is a problem solving strategy.

Necessary properties of an algorithm which is well designed-

1) A general solution to the problem

2) Clearly defined and unambiguous steps

3) Finite number of steps

4) Flow of control from one process to another

Ways of representing algorithms-

1) Narrative

2) Flow Charts

3) Pseudocode
Done By: Gideon Ramcharan

Constructs used in structured programming-

I/O statements

Sequencing- The logical flow of execution of a program

Refers to an ordered execution of statements

Selection/decision logic- One of a number of statements is executed depending on the state of the
programs.

Types- 1) Single Selection- Execute one set of instructions or do nothing (IF-THEN)

2) Dual-alternative selection- Execute one of two choices (IF-THEN-ELSE)

3) Case Selection- Executes one set of instructions based on multiple conditions


(IF-THEN-ELSE IF or Case Switch)

Iteration or Repetition (bounded and unbounded)-

This is where a set of instructions are repeated based upon the satisfaction of a specific
criteria (unbounded) or achieving a set number of times to be repeated (bounded).

Bounded Iteration- where there is a set start and stop value to execute a set of instructions (For
Loop)

Unbounded Iteration- Where execution is dependent on particular criteria to loop (While, Repeat
Until / Do While)
Done By: Gideon Ramcharan
GENERAL TERMS

Variables- a named container of a specific data type that can hold a value which may change
(are common in pseudocode)

Constant- is a value that never changes throughout the execution of an operation/program (are
capital in pseudocode)

Data Type- allows the system to know what type of operations can be performed on the data

Numerical Data Types- Integer, Real Numbers

Character Data Types- Single Character, String Character

Boolean or Logical Data Types- a variable that holds only true or false values

Functions

A function is a named set of instructions which is apart from where execution started and does a
specific task. It may or may not return a value and accepts 0 or more parameters/arguments.

[return value]functionName([value1],[value2])

Mathematical functions-

Sqrt(N)- returns the square root of N

Integer(N)- returns the integer value of a real number

Random()

String Fuctions-

Mid(S,n1,n2)- returns a set of n2 characters starting at position n1 in the string S

Length(S)- Returns the length of a string

to Num(S)- converts a string to a numerical value

to String(N)- converts a numerical value to a string

Date(), Time()
Done By: Gideon Ramcharan
Operators

Operators are used to compare/join two or more values and give a numerical/logical/Boolean
result.

Mathematical Operators- joins two numerical values and gives a numerical result

+-/*%^

Relational Operators- compares two values and gives a logical result

< > >= <= == != <>

Logical Operators- joins two boolean values and gives a logical result.

NOT AND OR

Arrays

A method that allows for multiple values to be stored in a single variable and individually
accessed via an index

Structures

An abstract data type that has multiple native variables used together to form a user defined
variable
Done By: Gideon Ramcharan

MODULE 3
Programming Paradigms

Procedural/Imperative-

A step by step approach to building programs where the order in


which the program executes is important

Properties- Incremental change of the program state over time

-Execution of computational steps in an order governed by


control structures

Examples- Basic, Pascal, C

Object Oriented-

Considers the representing of real world entities as “objects” with


behaviours and attributes.

These objects may then act as templates for other objects which can
inherit their behaviours and attributes or supersede their super classes
own.

Properties

-The theory of concepts & models of human interaction with


real world phenomena.

-Data as well as operations are encapsulated in objects

-Objects interact by message passing

-Classes are organized in inheritance hierarchies

Examples- Java, Python, C++, Visual Basic, Ruby


Done By: Gideon Ramcharan
Functional-

Where functions, not objects nor procedures, are used as the building
blocks of the program

In this sense, the functions are similar to mathematical equations


because they declare a relationship between two or more entities

Properties-

-Main idea is mathematics & the theory of functions

-All computations are done by applying functions

-Adds a layer of complexity of expression for solving problems

Examples- Haskell, Erlang

Declarative-

Where problems are described and the computer finds a solution

Is more concerned about the result than the means of finding it

Examples- Structured Query Language SQL, Prolog

Scripting-

Where a list of commands, called the script, are placed in a file to be


executed. The whole list of commands is not compiled by the CPU all
at once but rather interpreted one command at a time by another
program.

Examples- Unix Shell Scripts (ksh, csh, bash, sh) , VBScript,


JavaScript, PHP
Done By: Gideon Ramcharan
Stages of the compilation process

1) Lexical Analysis (Done by Lexer)-

The process whereby the sequence of characters in source code is


converted to a sequence of tokens (meaningful strings)

2) Syntax Analysis (Done by parser)-

The process whereby tokens from the lexer are converted into a node
on a syntax tree

3) Semantic Analysis (Done by parser)-

The process whereby the logic of the syntax tree is tested

4) Intermediate Code Generation-

The process whereby intermediate code, such as assembly language,


is built using a syntax tree, each node on the syntax tree has a
predefined template of intermediate code.

5) Code Optimization-

The process whereby the optimizer analyzes the intermediate code for
redundancies and useless code

It makes the program more efficient and compact.

6) Code Generation-

The process whereby the code generator converts some type of


intermediate code, such as assembly language, into machine language
Done By: Gideon Ramcharan

Assemblers, Compilers, Virtual Machines and Interpreters

Assemblers-

A utility program which converts assembly languages directly into


machine/object code

Compiler-

Converts source code (written in a high level programming language)


to another computer language (usually a low level one such as
assembly language or machine code)

Virtual Machines

A software based emulation of a computer.

Interpreters

A computer program that directly executes instructions written in a


programming or scripting language without previous batch compiling
them into machine language

Levels of programming Languages


Done By: Gideon Ramcharan
Low Level

Machine code

All programs are converted into machine code before they can
be executed.

Consists of combinations of 1’s and 0’1 that represent high and


low electrical voltage

This is the language that the CPU can ‘understand’

Assembly language

Uses symbolic operation code to represent the machine code

High Level

Programming Languages

Uses English like statements

Good Programming Style

White Space, Indentation, Appropriate Comments

Role of preprocessors and linkers

Preprocessor - a program/utility that takes a file that contains text (usually C


source code) with preprocessor directives and outputs a modified version of the file
by applying the directives to the text which is then passed to the compiler.

It performs preliminary operations, such as including files, to the code before the
compiler ‘sees’ it.

Linker- a program that takes in object files generated by a compiler and library
files and combines them into a single executable program.

The CPU (Central Processing Unit)


Done By: Gideon Ramcharan

CPU components
ALU(Arithmetic Logic Unit)

Performs all the mathematical calculations

Manipulates data by sorting, collating and comparing

Performs logical operations including reasoning and comparisons

CU(Control Unit)

Controls the flow of information to and from all components of the


computer.

Read/Interprets program instructions

Registers- special, small, high speed storage area within the CPU. The store
data/instructions or addresses to data/instructions that is to be processed by the
CPU.
Done By: Gideon Ramcharan
NAME Purpose

Memory Buffer Register(MBR) Contains the contents of data or instructions (a


word) read from or to be sent to memory or the
I/O module.

Memory Address Register(MAR) Holds the memory address of the


data/instructions to be read by the CPU or the
memory address to which the CPU is to write
data.

Memory Data Register(MDR) Temporarily stores data read from or written to


memory. All transfers from memory to the
CPU go via the MDR

Instruction Register Contains the instruction (op code) fetched by


the CPU from main memory.

Instruction Buffer Register It is employed to temporarily hold the right


hand instruction from a word in memory.

Program Counter Contains the address of the next instruction


pair to be fetched from memory for execution

Accumulator (AC) & Multiplier (MQ) Temporarily holds operands and results of
ALU operations.
Done By: Gideon Ramcharan

Instruction Format

An instruction must include and operation code (op code) and zero or more
operands.

Opcode- The operation to perform on the data

Operand- Specifies the data that is to be operated on or manipulated. By extension,


the data itself.

Instructions may have different numbers of addresses-

1) Zero address instructions OPCODE

-no address field is present

-uses PUSH and POP instructions

-stack is used, pops two operands from the stack and pushes the result
Example:

Evaluate X=(A+B)*(C+D)

PUSH A TOS <- A

PUSH B TOS <- B

ADD TOS<-A+B

PUSH C TOS <- C

PUSH D TOS <- D

ADD TOS<-C+D

MUL TOS<-(C+D)*(A+B)

POP M[X]<-TOS
Done By: Gideon Ramcharan

2) Single/One Address instructions

-uses and Accumulator register for all data manipulation

-a temporary register is used for multiplication and division

-Address can be a register name or memory address

Example:
OPCODE ADDRESS
X=(A + B)X(C + D)
LOAD A  ; AC <- M [A]
ADD B   ; AC <- AC + M[B]
STORE T ; M [T] <- AC
LOAD C  ; AC <- M [C]
ADD D   ; AC <- AC + M[D]
MUL T   ; AC <- ACxM[T]
STORE X ; M[X] <- AC

3) Two address instructions

-Two address registers or two memory locations are specified

-Assumes the destination address is the same as that of the first operand

Consider the example

OPCODE ADDRESS ADDRESS


X=(A + B)-(C + D)
MOV R1,A ; R1 <- M[A]
ADD R1,B ; R1 <- R1 + M [B]
MOV R2,C ; R2 <- M [C]
ADD R2, D ; R2<-R2 + M[D]
SUB R1,R2 ; R1 <- R1 - R2
MOV X,R1 ; M[X] <- R1
Done By: Gideon Ramcharan
4) Three address instructions

-Memory addresses for the two operands and one destination needs to be specified

-Each address fields can be used to specify either a processor or a memory operand

Let us consider the example


OPCODE ADDRESS ADDRESS ADDRESS
X=(A + B)*(C + D)
ADD R1,A,B; R1 <- M [A] + M [B]
ADD R2,C,D; R2 <- M [C] + M [D]
MUL X,R1,R2; M [X] <- Ri x R2

Bit allocation for instructions


8 bits:

OPCODE OPERAND
0 3 4 7

16 bits:

OPCODE OPERAND OPERAND


0 34 9 10 15

Fixed Length vs. Variable Length Instructions

FIXED VARIABLE
Arguably faster execution Uses less memory
Used in RISC (Reduced instruction set Used in CISC machines (Complex
computing) processors (PowerPC and Instruction set computer)
Alpha)
Memory space is wasted as all Each instruction uses the exact amount
instructions must occupy the same of memory space it requires
amount of memory even though the
instructions may not need that amount
Done By: Gideon Ramcharan
of memory space

Addressing Modes -Specifies a rule for interpreting or modifying the address field
of an instruction before the opcode is actually executed

1) Immediate-

The data needed by the processor is contained in the


instruction i.e. Operand=Address Field (A)

Eg. ADD 5

Add 5 to the contents of accumulator

5 is the operand

Advantage: No memory reference to fetch data, fast

Disadvantage: Limited Operand Magnitude

2) Direct-

Address Field(A) contains the address of the operand in


memory i.e. Effective Address=Address Field(A)

Eg. ADD A

Add contents of cell A to the accumulator

Look in memory at Address A for operand

Advantages: Single memory reference to access data, Simple, No additional


calculations to work out effective address

Disadvantage: Limited address space


Done By: Gideon Ramcharan

3) Indirect

Address Field(A) points to a memory cell


which contains the address of the operand i.e.
Effective address=(A). Look in the address
field (A), find effective address, (EA) and
look there for operand.

Eg. ADD (A)

Add contents of cell pointed to by the contents of A to the accumulator.

Advantage: Large Address Space 2n, where n is the word length

Disadvantage: Multiple memory reference to find operand, hence slower


Done By: Gideon Ramcharan
Instruction Cycle (Fetch, Decode & Execute)

FETCH

1) The instruction is placed in memory (for faster


execution)

2) The address of this instruction is then stored in


the Program Counter (PC)

3) The instruction is then loaded into the


Instruction Register (IR)

4) The Program Counter is then adjusted to


‘point to’ the next instruction

DECODE

5) The Control Unit (CU) then


decodes/interprets what the instruction is
supposed to do.

Where does the computer obtain the data?

Where the result should be sent?

Execute

6) The Control Unit (CU) then passes the decoded instruction to the Arithmetic
Logic Unit (ALU) where it is executed.
Done By: Gideon Ramcharan
Instruction Set- The basic types of instructions that the CPU can execute

Types-

ADD

COMPARE

INPUT

JUMP

JUMP IF

LOAD

OUTPUT

STORE

Cache Memory- Specialized fast memory near the CPU which holds data or
instructions that are frequently used, allowing for faster access times.

It temporarily holds information while instructions are being executed (awaiting


processing)

Clock Speed- Also called clock rate, the speed at which a microprocessor executes
instructions. Every computer contains an internal clock that regulates the rate at
which instructions are executed and synchronizes all the various computer
components. The CPU requires a fixed number of clock ticks (or clock cycles) to
execute each instruction. The faster the clock, the more instructions the CPU can
execute per second.
Clock speeds are expressed in megahertz (MHz) or gigahertz ((GHz).

Data Representation
Done By: Gideon Ramcharan
Decimal Binary Octal Hexadecimal Binary Coded Digit

0 0 0 0 0000

1 01 1 1 0001

2 10 2 2 0010

3 11 3 3 0011

4 100 4 4 0100

5 101 6 5 0101

6 110 7 6 0110

7 111 7 0111

8 1000 8 1000

9 1001 9 1001

10 1010 A (10) 1010

11 1011 B (11) 1011

12 1100 C (12) 1100

13 1101 D (13) 1101

14 1110 E (14) 1110

15 1111 F (15) 1111


Done By: Gideon Ramcharan
The Decimal System.

As we go left, the value of each digit is increased ten-fold.

Ten thousands thousands hundreds tens units

10 000 1000 100 10 1

The Binary System.

As we go left, the value of each digit is increased two-fold. First, determine the position value of
each digit. Write the value (weight) above each digit .

Working out the decimal equivalent of 110101

Thirtytwos sixteens eights fours twos units

25 24 23 22 21 20

weight 32 16 8 4 2 1

binary digit 1 1 0 1 0 1

Add the position value where a “1” appears 32 + 16 + 4 + 1 = 53.


Done By: Gideon Ramcharan

DECIMAL TO BINARY AND BINARY TO DECIMAL

Perform repeated divisions by 2 and save the remainders. The remainders, in order, from bottom
to top, forms the binary equivalent from right to left.

The binary equivalent of decimal 43 is:

43/2 = 21 remainder 1

21/2 = 10 remainder 1

10/2 = 5 remainder 0

5/2 = 2 remainder 1

2/2 = 1 remainder 0

1 / 2 = 0 remainder 1

The remainders from bottom to top form the binary equivalent from left to right, thus:

43 = 101011

BINARY ADDITION

Very rarely will we find it necessary to add more than two binary numbers at any one time.

1. If we add a binary zero to another binary zero, the result will be binary zero.
1. If we add a one to a zero (or zero to one) the result will be one.
1. If we add a one to a one in decimal the answer is two, but in binary there is no such thing as
a binary digit “2”. We must carry a binary digit “1” to the next position to the left.
0 0 1 1

+0 +1 +0 +1

0 1 1 10

E.g.

Add binary 110 and binary 101: 110


Done By: Gideon Ramcharan
+101

1011

BINARY SUBTRACTION

Just as we carry the value two in binary addition, so, in subtraction, we need to borrow two
sometimes in order to subtract.

1. If we were to subtract 1 from 10, we would expect the answer to be 1 since 1 + 1 =10 in
binary.
02

10 10

-1 -1 Just as in decimal, we can borrow 10 from the place to the left in order to

1 1 subtract, so, in binary, we can borrow 2 before subtracting.

E.g.

Subtract binary 111 from 1001 :

12
1001
-111

0100
Done By: Gideon Ramcharan

BINARY FRACTIONS

Convert to Binary Fraction to Decimal

100.10112

The positions after the decimal (1) .5 or ½ ; (2) .25 or 1/4 ; (3) .125 or 1/8; (4) .0625 or 1/16

.5

.0

.125

.0625

.6875 Answer = 4.6875

Convert Decimal to Binary: The whole number is calculated using the division by 2. (Multiply
by the fraction part until 0 is realized) the answer is written downwards using the values before
the decimal.

4.6875 4= 100 .6875 X 2

1.375 X 2

0.750 X 2

1.500 X 2

1.000 Answer = 100.1011


Done By: Gideon Ramcharan
CONVERSION OF DECIMAL TO OCTAL AND HEXADECIMAL

Convert 10910 to Octal

109/8 = 13 remainder 5

13/8 = 1 remainder 5

1/8 = 0 remainder 1 Ans = 1558

Convert 10910 to Hexadecimal (see table

109/16 = 6 remainder 13

6/16 = 0 remainder 16 Ans = 6D16

Conversion of Octal and Hexadecimal to Binary

Use 3 bits to represent the binary of each digit in Octal Nos. and 4 bits to represent the binary of each
digit in Hexadecimal.

Octal To Binary Hexadecimal to Binary

1 5 5

001 101 101


Done By: Gideon Ramcharan
BINARY CODED DECIMAL(BCD)

Representing integers using binary coded digit

Use 4 bits to represent each digit. Use 1010 for positive and 1011 for negative integers.g;-

Convert The Decimal Number 358 To Binary Coded Digit

+ 3 5 8

1010 0011 0101 1000

REPRESENTING INTEGERS – SIGN AND MAGNITUDE

An integer is a whole number, negative or positive. It is easy to convert a positive integer from
decimal to binary. The larger the number we wish to represent the more bits required.

Sign and magnitude.

Using 4 bits, one bit is used for the sign of the number : 0 for positive, 1 for negative. The
remaining 3 bits are used to store the binary equivalent of the number (without the sign).

e.g. +5 is represented

0 101

sign bit binary equivalent

Since the maximum value that can be stored with 3 bits is 7, the range of integers which can be
represented is -7 to +7.
Done By: Gideon Ramcharan
TWO’S AND ONE’S COMPLEMENT REPRESENTATION

Please note Two’s Complement is used for negative numbers not positive numbers.

E.g. You are asked to find the two’s Complement of +4 and -5 using 4 bits.

For +4, You first find the binary of 4 and add 0 to make up number of bits required i.e. 0100

For -4, You first find of the binary of 4, then add 0s to make up number of bits required, then
find the One’s Complement of the number, then Two’s Complement.

● 0100 – Binary of 4 using 4 bits


● 1011 – One’s Complement of (change 0s to 1s and 1s to 0s)
● 1100 – Two’s Complement of (add 1 to One’s Complement)

● Two’s Complement.
The two’s complement of a binary number is obtained by adding 1 to its one’s complement. E.g.
The 4-bit one’s complement of 0110 is 1001. Therefore, the 4-bit two’s complement of 0110 is
1001

+ 1

1010
Done By: Gideon Ramcharan
FLOATING POINT REPRESENTATION

What number is represented by 0 010 1010


1 23 4

1. Sign for Mantissa i.e 1 for negative and 0 for negative

2. Sign for Exponent i.e 1 for negative and 0 for negative (the exponent values are 00 for 0; 01
for 1; 10 for 2 and 11 for 3.

3. Mantissa value

Please note a positive sign for the exponent means to move the decimal of the mantissa to the
right according to the value of the exponent and a negative sign for the exponent means to move
the decimal point to the left according to the value of the exponent, placing a 0 to indicate no. of
times move to the left.

Therefore the number represented is:

0.1010 x 22 = 10.102 = 2.510

Number represented by 1 001 1100 is -0.1100 x 21 = 1.1002 = -1.510

Number represented by 0 101 1100 is 0.1100 x 2-1 = 0.011002 = (0.25 + 0.125)10 = 0.37510

Number represented by 0 111 0001 is 0.0001 x 2-3 = 0.00000012 = 1/128 = 0.007812510

The largest positive number is represented by 0 011 1111


which is 0.11112 x 23 = 111.12 = 7.510

Convert Binary Fractions to Floating Point Representations


Done By: Gideon Ramcharan
Accurate representation

What is the representation of the following:

2.75= 10.112 = 0.10112 x 22 = 0 010 1011

-6.5 = 110.12 = 0.11012 x 23 = 1 011 1101

0.1875 = 0.00112 = 0.00112 x 20 OR 0.01102 x 2-1 OR 0.11002 x 2-2

Therefore 0 000 0011

0 101 0110

0 110 1100

Character Codes

- are a set of binary patterns used to represent the character set. E.g.

● ASCII (American Standard Code for Information Interchange) it is the commonest code. It
is 7-bit code and it handles up to 128 characters i.e. 27.
● EBCDIC (Extended Binary Coded Decimal Interchange Code). It is an 8-bit code which
therefore permits 256 characters i.e. 28.

You might also like