0% found this document useful (0 votes)
4 views35 pages

Central Processing Unit

Uploaded by

ambrose.njeru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views35 pages

Central Processing Unit

Uploaded by

ambrose.njeru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Central

Processing
Unit
By: Ambrose Njeru [BSc, Msc] 1
Central Processing Unit

By: Ambrose Njeru [BSc, Msc] 2


Central Processing Unit
❖The Central Processing Unit (CPU) is the brain of
any computer system.
❖It controls the functioning of the other units and
process the data.
❖The CPU is sometimes called the processor, or in the
personal computer field called “microprocessor”.
❖It is a single integrated circuit that contains all the
electronics needed to execute a program.
❖The processor calculates (add, multiplies and so on),
performs logical operations (compares numbers and
make decisions), and controls the transfer of data
among devices. By: Ambrose Njeru [BSc, Msc] 3
Central Processing Unit
❖The CPU is the portion of a computer system that
carries out the instructions of a computer program,
and is the primary element carrying out the
computer's functions.
❖The CPU is responsible for handling all
instructions and calculation it receives from other
hardware components in the computer and
software programs running on the computer.
❖The fundamental operation of most CPUs,
regardless of the physical form they take, is to
execute a sequence of stored instructions called a
program. By: Ambrose Njeru [BSc, Msc] 4
Central Processing Unit
❖The CPU is made up of three main components:
❖The control unit.
❖The registers.
❖The arithmetic and logic unit.
1. The control unit
❖Controls the flow of data within the system.
❖Also controls and monitors communications
between the hardware attached to the computer. It
controls the input and output of data, checks that
signals have been delivered successfully, and makes
sure that data goes to the correct place at the correct
time. By: Ambrose Njeru [BSc, Msc] 5
Central Processing Unit
2. Registers
❖Registers are a type of computer memory used to
quickly accept, store, and transfer data and
instructions that are being used immediately by the
CPU. The registers used by the CPU are often
termed as Processor registers.
❖A processor register may hold an instruction, a
storage address, or any data (such as bit sequence or
individual characters).
❖The computer needs processor registers for
manipulating data and a register for holding a
memory address. By: Ambrose Njeru [BSc, Msc] 6
Central Processing Unit
❖The register holding the memory location is used
to calculate the address of the next instruction after
the execution of the current instruction is
completed.
❖The following is the list of some of the most
common registers used in a basic computer:
❖Data register (DR) - Holds memory operand.
❖Accumulator (AC) - Processor register.
❖Memory Address register (MAR) - Holds the
address of the main memory to or from which
data is to be transferred.
By: Ambrose Njeru [BSc, Msc] 7
Central Processing Unit
❖Memory Data Registers (MDR) - Contains the
data to be written into or read from the
addressed word of the main memory.
❖Instruction register (IR) - Holds instruction
that is currently being executed.
❖Program counter (PC) - Holds address of
the instruction. Monitors the execution of
instructions. It keeps track on which instruction
is being executed and what the next instruction
will be.
❖Temporary register (TR) - Holds temporary
data. By: Ambrose Njeru [BSc, Msc] 8
Central Processing Unit
❖Input register (INPR) - Carries input character.
❖Output register (OUTR) - Carries output
character.
3. Arithmetic and logic unit (ALU)
❖ALU is where the CPU performs the arithmetic and
logic operations. Every task that your computer carries
out is completed here. The ALU’s operations fall into
two parts:
❖The arithmetic part, which deals with calculations,
e.g. 1 + 2 = 3.
❖The logic part, which deals with any logical
comparisons, e.g. 2>1
By: Ambrose Njeru [BSc, Msc] 9
Logic Gates
❖Binary information is represented in digital
computers by physical quantities called signals.
❖Electrical signals such as voltages exist throughout
the computer in either one of the two recognizable
states.
❖The two states represent a binary variable that can be
equal to 1 or 0.
❖At the core level, computer communicates in the
form of 0 and 1, which is nothing but low and high
voltage signals.
❖Different operations are performed on these signals
by use of different logic Gates.
By: Ambrose Njeru [BSc, Msc] 10
Logic Gates
❖Logic gates are blocks of hardware that produce
graphic symbol and its operation can be described by
means of an algebraic expression.
❖The input-output relationship of the binary variables
for each gate can be represented in tabular form by a
truth-table.
❖Each gate with more than one input is sensitive to
either logic 0 or logic 1 input at any one of its inputs,
generating the output according to its function.
❖The various logical gates are: AND, OR, NOT, NAND,
NOR, XOR and XNOR.
By: Ambrose Njeru [BSc, Msc] 11
Logic Gates
1. AND Gate
❖The AND gate produces the AND logic function, that
is, the output is 1 if input A and input B are both
equal to 1; otherwise, the output is 0.
❖The algebraic symbol of the AND function is the
same as the multiplication symbol of ordinary
arithmetic.
❖We can either use a dot between the variables or
concatenate the variables without an operation
symbol between them. AND gates may have more
than two inputs, and, the output is 1 if and only if all
inputs are 1.
By: Ambrose Njeru [BSc, Msc] 12
Logic Gates

By: Ambrose Njeru [BSc, Msc] 13


Logic Gates
2. OR Gate
❖The OR gate produces the inclusive-OR function;
that is, the output is 1 if input A or input B or both
inputs are 1; otherwise, the output is 0.
❖The algebraic symbol of the OR function is +, like
arithmetic addition. OR gates may have more than
two inputs, and the output is 1 if any input is 1.

By: Ambrose Njeru [BSc, Msc] 14


Logic Gates
3. Inverter(NOT) Gate
❖The inverter circuit inverts the logic sense of a binary
signal. It produces the NOT, or complement,
function.
❖The algebraic symbol used for the logic complement
is either a prime or a bar over the variable symbol

By: Ambrose Njeru [BSc, Msc] 15


Logic Gates
4. NAND Gate
❖The NAND function is the complement of the AND
function, as indicated by the graphic symbol, which
consists of an AND graphic symbol followed by a
small circle.
❖The designation NAND is derived from the
abbreviation of NOT-AND.

By: Ambrose Njeru [BSc, Msc] 16


Logic Gates
5. NOR Gate
❖The NOR gate is the complement of the OR gate
and uses an OR graphic symbol followed by a small
circle.

By: Ambrose Njeru [BSc, Msc] 17


Logic Gates
6. Exclusive-OR Gate
❖The exclusive-OR gate has a graphic symbol similar to
the OR gate except for the additional curved line on the
input side.
❖The output of the gate is 1 if any input is 1 but excludes
the combination when both inputs are 1. It is similar to
an odd function; that is, its output is 1 if an odd number
of inputs are 1.

By: Ambrose Njeru [BSc, Msc] 18


Logic Gates
7. Exclusive-NOR Gate
❖The exclusive-NOR is the complement of the exclusive-
OR, as indicated by the small circle in the graphic
symbol.
❖The output of this gate is 1 only if both the inputs are
equal to 1 or both inputs are equal to 0.

By: Ambrose Njeru [BSc, Msc] 19


Instruction Codes
❖An instruction code is a group of bits that tells the
computer to perform a specific operation part.
❖Instruction Code: Operation Code
❖The operation code of an instruction is a group of bits
that define operations such as add, subtract, multiply,
shift and compliment.
❖The number of bits required for the operation code
depends upon the total number of operations available
on the computer.
❖The operation code must consist of at least n bits for a
given 2^n operations. The operation part of an
instruction code specifies the operation to be
performed. By: Ambrose Njeru [BSc, Msc] 20
Instruction Codes
❖Instruction Code: Register Part
❖The operation must be performed on the data
stored in registers.
❖An instruction code therefore specifies not only
operations to be performed but also the registers
where the operands(data) will be found as well as
the registers where the result must be stored.

By: Ambrose Njeru [BSc, Msc] 21


Instruction Codes
❖The basic computer has three instruction code
parts. The three parts are:
1. Memory Reference Instruction - It uses 12 bits
to specify the address and 1 bit to specify the
addressing mode (I). I is equal to 0 for direct
address and 1 for indirect address.
2. Register Reference Instruction - These
instructions are recognized by the opcode 111 with
a 0 in the left most bit of instruction. The other 12
bits specify the operation to be executed.

By: Ambrose Njeru [BSc, Msc] 22


Instruction Codes
3. Input-Output Instruction - These instructions
are recognized by the operation code 111 with a 1 in
the left most bit of instruction. The remaining 12
bits are used to specify the input-output operation.
❖The format of an instruction is depicted in a
rectangular box symbolizing the bits of an
instruction. Basic fields of an instruction format are:
1. An operation code field that specifies the
operation to be performed.
2. An address field that designates the memory
address or register.
By: Ambrose Njeru [BSc, Msc] 23
Instruction Codes
3. A mode field that specifies the way the
operand of effective address is determined.
❖Computers may have instructions of different
lengths containing varying number of addresses.
The number of address field in the instruction
format depends upon the internal organization of
its registers.

By: Ambrose Njeru [BSc, Msc] 24


Instruction Codes
❖Examples of instructions in instruction set.
1. ADD - Add two numbers together.
2. COMPARE - Compare numbers.
3. IN - Input information from a device, e.g.,
keyboard.
4. JUMP - Jump to designated RAM address.
5. JUMP IF - Conditional statement that jumps to a
designated RAM address.
6. LOAD - Load information from RAM to the CPU.
7. OUT - Output information to device, e.g., monitor.
8. STORE - Store information to RAM.
By: Ambrose Njeru [BSc, Msc] 25
Fetch Execute Cycle
❖The fetch execute cycle is the basic operation
(instruction) cycle of a computer (also known as the
fetch decode execute cycle).
❖During the fetch execute cycle, the computer
retrieves a program instruction from its memory. It
then establishes and carries out the actions that are
required for that instruction.
❖The cycle of fetching, decoding, and executing an
instruction is continually repeated by the CPU
whilst the computer is turned on.

By: Ambrose Njeru [BSc, Msc] 26


Fetch Execute Cycle
❖The cycle involves the following steps:

By: Ambrose Njeru [BSc, Msc] 27


Fetch Execute Cycle
1. Fetch the Instruction: The next instruction is
fetched from the memory address that is
currently stored in the program counter and
stored into the instruction register. At the end of
the fetch operation, the PC points to the next
instruction that will be read at the next cycle.
2. Decode the Instruction: During this stage, the
encoded instruction presented in the instruction
register is interpreted by the decoder.

By: Ambrose Njeru [BSc, Msc] 28


Fetch Execute Cycle
3. Read the Effective Address: In the case of a
memory instruction (direct or indirect), the
execution phase will be during the next clock
pulse. If the instruction has an indirect address,
the effective address is read from main memory,
and any required data is fetched from main
memory to be processed and then placed into
data registers. If the instruction is direct, nothing
is done during this clock pulse. If this is an I/O
instruction or a register instruction, the operation
is performed during the clock pulse.

By: Ambrose Njeru [BSc, Msc] 29


Fetch Execute Cycle
4. Execute Stage: The control unit of the CPU passes the
decoded information as a sequence of control signals to
the relevant function units of the CPU to perform the
actions required by the instruction, such as reading
values from registers, passing them to the ALU to
perform mathematical or logic functions on them, and
writing the result back to a register. If the ALU is
involved, it sends a condition signal back to the CU. The
result generated by the operation is stored in the main
memory or sent to an output device. Based on the
feedback from the ALU, the PC may be updated to a
different address from which the next instruction will
be fetched.
5. Repeat Cycle By: Ambrose Njeru [BSc, Msc] 30
Fetch Execute Interrupts
❖Interrupts are signals generated by a hardware
device or by a software application that tell the CPU
it needs some CPU time.
❖A CPU can only ever do one job at a time. If it is
working on one job and another job needs some
CPU processing time then that other job sends a
signal, an interrupt, to the processor. When the
processor receives the signal, it does one of a
number of things.
❖The CPU might stop what it is doing and start
servicing the device or software that sent the signal.
By: Ambrose Njeru [BSc, Msc] 31
Fetch Execute Interrupts
❖The CPU might carry on doing its current job until it is
finished and then service the device or software that sent
the signal.
❖The CPU might carry on doing its current job and then
service other interrupts that have happened. When it has
done those, it then services the interrupt in our
discussion!
❖There are different kinds of interrupts:
1. A timer interrupt - This is an interrupt that occurs at
fixed time intervals. There are circuits in a computer
that can generate an interrupt signal every 1 ms, for
example. This could then be used to signal to the CPU
to refresh the VDU, for example.
By: Ambrose Njeru [BSc, Msc] 32
Fetch Execute Interrupts
2. A program error interrupt - When a program is
written, it may need to do maths sums! If you
divide any number by zero, the result is
meaningless and the program you are running will
get confused! The CPU needs to know about this,
so a 'program error' interrupt signal is sent to the
CPU to tell it what has happened. The CPU can
then take action, for example, by ending the
program and reporting the error.

By: Ambrose Njeru [BSc, Msc] 33


Fetch Execute Interrupts
3. A hardware error interrupt - Your computer is
made up of a lot of different hardware devices.
Generally, they work well and do what they are
supposed to do. But like any electrical or
mechanical device they will one day fail. When
that happens, the CPU needs to know about it. A
device that has failed sends an interrupt signal to
the CPU. The CPU can then, for example, put a
message on the screen to notify the user of the
problem.

By: Ambrose Njeru [BSc, Msc] 34


Fetch Execute Interrupts
4. I/O interrupts - When a file is sent to a printer, it will go
to a buffer. The buffer will then communicate with the
printer. The reason for this is that it frees up the CPU to do
other jobs. Remember, the CPU can only do one job at a
time. If it is managing the printing of a file, it can't be
doing other things. This, however, isn't a very efficient use
of CPU time because printing is slow compared to the
speed CPUs work at. Another example of an I/O interrupt
is when you press a key, an interrupt is sent to the CPU.
The CPU stops what it is doing and then manages the
reading in of the key code into a buffer. Then it goes back
to doing what it was doing before. At some point, the CPU
will return to the keyboard buffer and retrieve the contents
for use somewhere.
By: Ambrose Njeru [BSc, Msc] 35

You might also like