0% found this document useful (0 votes)
8 views

Basic Computer Operations(3)(2)(2)

Uploaded by

pranav.garg1006
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)
8 views

Basic Computer Operations(3)(2)(2)

Uploaded by

pranav.garg1006
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/ 59

Basic Computer Operations

Introduction to Computational Thinking 2


Lesson Outcomes

At the end of this lesson, you should be able to:


• Describe the basic organization and modules in a basic computer

• Describe the information representations used by a computer

• State the functional units in the Central Processing Unit (CPU) of a computer

• Describe the main functions of each units within the CPU

• Articulate the stages involves in typical CPU operations

Introduction to Computational Thinking 3


Topic Outline

Basic Computer Organization


and Information Representations

Basic Central Processing Unit (CPU) Structure

Basic CPU Operations

Introduction to Computational Thinking 4


Basic Computer Organization and
its Information Representations

Introduction to Computational Thinking 5


Basic Computer Organization

• Central Processing Unit (CPU) (Examples)


keyboard monitor
- processes information
- performs operations based on information given
I/O
• Memory CPU Memory
Interface
- stores information used by the computer

System Bus
• Input/ Output (I/O) Interface Data bus

- mechanism for transferring information to and from Address bus


the outside world, such as to interact with users
Control bus
• System Bus
Microprocessor
- providing the connection between the modules

In practice, these modules are now commonly integrated together in


one component and known as the Microprocessor (μP).

Introduction to Computational Thinking 6


What are the types of
information, and how are they
represented in a computer
system?

Introduction to Computational Thinking 7


Types of Information

Consider the following arithmetic operation:


2+3

The given arithmetic contains two types of information:

• Instruction: to perform addition operation

• Data: using the two numbers with values of 2 and 3

In what form is the information presented to the computer?

Introduction to Computational Thinking 8


Information Representation

Microprocessor in a computer is a digital device.


It consists of electronic components (e.g. transistor)
that operate in two states (either turn-on or turn-off).

Conveyed in the form of voltage Represented by using binary digit


levels: (or one bit in short form):

• Low voltage (0 volt) • ‘0’ for low voltage

• High voltage (depends on the • ‘1’ for high voltage


power supply used by μP)

Introduction to Computational Thinking 9


Information representation using binary bits is known as in
Binary Format.

Introduction to Computational Thinking 10


Binary Format

A datum (e.g. a number) that consists of one bit:


• can only have two values: either 0 or 1
• is not very useful in practice

Hence, multiple bits are combined together to give a wider range (or more variety of combinations).

Example of a number using 4 bits:


10102 (or written as 1010b)

The subscript ‘2’ or ‘b’ means the number should be interpreted using a base-2 numeral system.

Introduction to Computational Thinking 11


Value of Binary Number

Example of an 8-bit binary number: 01001101b


General expression for an n-bit binary number: bn-1…bk…b2b1b0

Each bit has a weightage corresponding to its bit position.


The decimal (base-10) value of the n-bit (unsigned) number can hence be calculated as:

2n-1 × bn-1 +…+ 2k × bk +…+ 22 × b2 + 21 × b1 + 20 × b0

- the kth bit will have a weightage of 2k.

Example:
Decimal value of 0110b 0110b = 23 × 0 + 22 × 1 + 21 × 1 + 20 × 0
= 0 + 4 + 2 + 0
≡ 610
Introduction to Computational Thinking 12
Hexadecimal Format

Base-2 binary format: most conveniently used by the computer but it is not human-friendly.
e.g. 1011010101101100b

To make it easier for human to read (and write) binary data, base-16 hexadecimal format
is normally used instead.

Hexadecimal symbols: 0, 1, 2, … 8, 9, A, B, C, D, E, F

Each hexadecimal symbol (digit) ≡ four (4) binary bits

To convert between the two formats, the binary format data is separated into groups of four (4) bits.

What is the decimal value of the number


e.g. 1011010101101100b Ξ B56Ch
represented by the 16-bit data?

Introduction to Computational Thinking 13


Data Size/ Data Width

Conventions used to describe data size/ data width in microprocessor/ computer:

• one Byte = 8 bits (2 hex digits)

• one Nibble = 4 bits (1 hex digit)

• one Word = 16 bits or 32 bits, depending on the natural data size/ data width of the
CPU architecture

32-bit word will be used in this course.

• one DWord = 64 bits

Introduction to Computational Thinking 14


Microprocessor
Basic Structure

Introduction to Computational Thinking 15


Outline

Simplified Model of a Microprocessor Structure that consists of the


Three Modules connected by the System bus:
• Memory

• CPU

• Input/ Output Interface

• System bus

Introduction to Computational Thinking 16


Basic Computer Organization

Recap

• Central Processing Unit (CPU) keyboard monitor


- processes information

• Memory CPU Memory


I/O
- stores information used by the computer Interface

System Bus
• Input/ Output (I/O) Interface Data bus

- interact with users Address bus

Control bus
• System Bus
- providing the connection between the
Microprocessor
modules

Introduction to Computational Thinking 17


Basic CPU Internal Structure

CPU
Three main Functional Units within the CPU:
• Control Unit (CU) REG
- controls and coordinates the overall operation of the
ALU REG
CPU
REG
• Arithmetic/ Logic Unit (ALU)
- performs the arithmetic operations as well as Boolean
logic functions
:
CU
REG
• Register Array
- holds the various information used by CPU operations

These functional units are connected internally by wires that System Bus
are extended to the external system bus.

Introduction to Computational Thinking 18


Aside: CPU Size

Early Computers’ CPU


Modern Computers’ CPU

large units of electronics circuits integrated circuit-based,


that take up much space i.e., part of the microprocessor

Introduction to Computational Thinking 19


Basic CPU Functional Units

CPU internal consists of the following:

1 Arithmetic and Logic Unit (ALU) 2 Control Unit (CU)

• deals with arithmetic operations • consists of decoders and logic


like addition, subtraction, circuits
multiplication and division (if
supported) • controls the overall operations of
the various units and modules
• also performs logic operations (i.e.
Boolean operations) • driven by a clock signal to ensure
that everything happens at the
AND, OR, NOT, XOR etc., and correct instances and in proper
bit shifting/ rotation sequence

Introduction to Computational Thinking 20


Basic CPU Functional Units (Cont’d)

3 Register Array Data, Address and Control signals

• a small amount of very high speed • comprises of signaling wires that


internal storage used for frequently are grouped into data signals,
accessed data address signals, and control
signals
• enables data to be stored and
retrieved quickly • the signals connect the various
internal functional units together
Some of these registers are used for
more specific functions. • extend to the external system bus
• e.g. program counter, instruction for other modules (memory and
register, stack pointer, memory I/O) of the μP
address register, accumulator, etc.

More on this later..

Introduction to Computational Thinking 21


System Bus

The system bus consists of groups of parallel signals that are used to transfer information
between the modules in the microprocessor.

Data Bus - conveys the information from one module I/O


CPU Memory
to the other. Interface

System Bus
Control Bus - provides the control signals for the Data bus

modules to work together, such as to determine the Address bus


direction of data flow, and when each device can
access the data bus and address bus. Control bus

Address Bus used to convey the address information.


The signals’ pattern on the address bus lines
determines the location of the source and destination
of the data transfer.

Introduction to Computational Thinking 22


Memory

Memory is used to store instructions and data for the CPU


• consists of high speed electronics components that store the Address Memory
information in binary bit format 2n-1

:
Each location stores an 8-bit (byte) size data. :
:
2
Each location is allocated a unique address.
1
• identified by specifying its binary pattern on the address bus
0

If data is more than 8 bits in size (e.g. a 32-bit word), 8 bits

• consecutive locations are used


• the lowest byte address is used to access the word location

Introduction to Computational Thinking 23


Memory Size

Memory size refers to the total number of locations that a memory


module can support. Address Memory
2n-1
This is dependent on the number of bits (n) used in its address bus:
• memory size = 2n bytes :
:
:
When n = 10
2
• 210 ≡ 1024 bytes.
• known as 1 KiloByte (KB) 1

0
When n = 20 8 bits
• 220 ≡ 1024 × 1KB = 1KB × 1KB is known as 1 MegaByte (MB)

When n = 30
• 230 ≡ 1KB × 1KB × 1KB is known as 1 GigaByte (GB)

Introduction to Computational Thinking 24


CPU, Memory and System Bus

CPU Memory

REG MEM
MEM
REG
ALU MEM
REG .
System .
:
CU Bus MEM
REG
MEM

Introduction to Computational Thinking 25


Program
Execution

Introduction to Computational Thinking 26


Outline

How Program Instructions are Executed


• How various parts of a program are recognized

• How the CPU and memory work together when executing a program

• The role of the different functional units within the CPU module

Introduction to Computational Thinking 27


Program and Instructions

Operation of the computer is determined by a


sequence of instructions that are given by the user
• collectively known as a program
• in more generic term – software
(as against the hardwired hardware circuitry that
cannot be changed).

All instructions are encoded in binary format when


loaded in the memory, together with the data.

Hence, the codes representing the instructions look just


like those for numbers and data when stored in memory
• but they are interpreted as commands (rather than
numeric data) when retrieved by the CPU.

Introduction to Computational Thinking 28


Aside: Instructions and Data

A program is typically permanently stored in a non-volatile storage


device, such as hard disk or flash memory (e.g. SD Card).
• first copy to the memory when it is ready to be executed
SD Card Random Access Memory

In addition to the instructions to be executed, a program will also need


to have access to data that its instructions need to act upon. Adobe Flash

• e.g. Adobe Flash Player: a program that can be used to view a


video clip stored as a data file

When a program is loaded in the memory, the memory will hence contain the following information:
• instructions to be executed
• data needed by the relevant instructions

Introduction to Computational Thinking 29


Program Execution

When a microprocessor executes a program


• it just executes the instructions in the given sequence.

Each instruction is in turn executed in a sequence of three basic steps:

Fetch

Decode

Execute

Introduction to Computational Thinking 30


Basic CPU Operations

Introduction to Computational Thinking 31


Machine Instruction

When the microprocessor starts operations, instructions are fetched (i.e.


retrieved) from memory successively into the CPU by the CPU’s Control Unit
for decoding.

Each instruction located in the memory is encoded in certain binary formats.


(also written in hexadecimal format for ease of reading by human).
• e.g. 01011101b (or 5Dh)
This is known as the Machine Instruction.

Hence, machine instructions stored in memory looks exactly like data.

So, how does the CPU know whether the content retrieved is an
instruction or data (e.g. an unsigned integer)?

Introduction to Computational Thinking 32


Instructions Executions

Valid machine instructions of a microprocessor family are encoded in specific binary bit patterns
• known as the instruction set of that microprocessor

CPU is designed to recognize its own instructions


• provided it fetches the instructions from the memory properly

Once the CPU successfully decodes a valid instruction


• execution is then performed
- such as applying an arithmetic operation on certain specified data

Introduction to Computational Thinking 33


Stored-Program Model

To understand how the CPU works, the simple stored-program model will be used here
• where both instruction and data are stored in the memory
CPU Memory

REG -

ALU Data
REG
System Data
REG Bus
.
. .
CU
. Instr
REG Instr

Introduction to Computational Thinking 34


Registers and Memory

A ‘Register’ is a very fast


storage located within the
CPU Memory
CPU.
• Individual register within the REG A yyh
CPU is identified by a label REG B
ALU
such as ‘A’, ‘B’, …; or ‘R0’,
‘R1’, … REG C
:
• Memory location is identified : 02h
System
by its (hexadecimal) address: CU 01h
‘00h’, ‘01h’, …, ‘38h’, …, etc. REG x Bus
00h

Introduction to Computational Thinking 35


Basic CPU Operation

Example
Addition Instruction: CPU Memory
Var1 = Num1 + Num2 REG A yyh
ALU
REG B
.
61h Num1
Assumptions:
REG C 60h Num2
• Num1 is stored in memory .
location 61h. . System 40h Var1
• Num2 is stored in memory CU . Bus .
location 60h. 01h
REG x
00h
• Var1 is stored in memory
location 40h.

Introduction to Computational Thinking 36


Basic CPU Operation (Cont’d)

Example
Addition Instruction: CPU Memory
Var1 = Num1 + Num2 Num1
REG A yyh
Num1
ALU
+
Num2
REG B
.
Num2 Num1
Execution: CU carries out 61h
REG C 60h Num2
the addition operation
.
• Num1 is copied to (loaded . System 40h Var1
into) Register A
CU . Bus .
• Num2 is copied to Register B 01h
REG x
00h
• ALU executes the Addition
operation: REG A + REG B

Introduction to Computational Thinking 37


Basic CPU Operation (Cont’d)

Example
Addition Instruction: CPU Memory
Var1 = Num1 + Num2 Num1
REG A yyh
Num1
ALU
+
Num2
REG B
.
Num2 Num1
Execution: CU carries out 61h
REG
Num1 C
+ Num2
60h Num2
the addition operation
.
• Result of ALU operation is . System 40h Var1
Num1 + Num2
moved into Register C.
CU . Bus .
• Content of Register C is 01h
REG x
copied (stored) into memory 00h
location 40h.

Introduction to Computational Thinking 38


Basic Operation Example

Example
Let Num1 value = 03h, CPU Memory
Num2 value = 15h, 03hA
REG yyh
03hALU
+ 15h
= 18h 15hB
REG
.
and Var1 = xxh 61h Num1
03h
(i.e. it doesn’t matter) 18hC
REG 60h Num2
15h
.
. System 40h xxh
18h
Var1
CU . Bus .
01h
REG x
00h

Introduction to Computational Thinking 39


Instruction Execution

On power up, the A clocking signal Based on the The CU of a CPU


program is also applied to rising/ falling is designed to
instructions will be the CPU (as well edges of the recognize its own
typically first as to the rest of clock, the CU will instructions and
loaded into certain the retrieve (fetch) the performs the
default memory microprocessor instruction from he corresponding
locations (together system). default memory operation coded.
with data). location.

How does the CU know where to find the instructions?

Introduction to Computational Thinking 40


Control Unit (CU) Operations

CPU
REG A
ALU REG B

REG C To be able to fetch and


execute the instruction,
Clock signal
CU : several other registers
will be needed.
(GHz in modern REG x
computer)

Instructions

Introduction to Computational Thinking 41


PC and IR

CPU contains another two special CPU


function registers:
REG A
• Program Counter (PC) ALU
REG B
- tells CU where to find the instruction in the
memory REG C

• Instruction Register (IR) CU :


REG x
- holds the copy of the instruction to be decoded
and executed by the CU
Instruction Register

Practical CPU will contain several other registers, Program Counter


e.g., stack pointer, status register etc.

Introduction to Computational Thinking 42


Fetch-Decode-Execute Cycle

Each operation cycle of the stored-program CPU typically involves three (3) basic steps:

Fetch the instruction from the


Execute the instruction memory into IR
• E.g., load the Fetch • using the address indicated by
operands into the the PC
ALU and get the ALU
to operate on them
Execute

Decode Decode the machine


instruction (by CU), which is
now stored in IR

Introduction to Computational Thinking 43


An Illustrative Example

After power-on,

• memory is loaded
with program and
data

• Program Counter’s
content is set to
‘00h’ (by design)

Introduction to Computational Thinking 44


An Illustrative Example (Cont’d)

Assumption for the Illustrative


Recall Instruction Set CPU Example:

• The set of instructions understood by a CPU “3A” is the code that means “Load
is specific to that particular CPU, which is Register A from memory”.
determined by the designer of the CPU.
• Hence each CPU has its own “language”, Note: This will have a totally different
which is known as its instruction set. meaning for another CPU family
• Examples: (E.g. It could be interpreted as “multiply”).

- Typical PC and notebooks use the x86


instruction set.
- Most tablets and smart phones use the
ARM instruction set.

Introduction to Computational Thinking 45


An Illustrative Example (Cont’d)

Back to Example

After power-on,

• memory is loaded
with the program
and data

• PC content is set to
‘00h’ (by design)

Introduction to Computational Thinking 46


An Illustrative Example (Cont’d)

Fetch 1
• Content of location
00h and 01h are
loaded (or fetched)
into IR (assume 16-
bit size instruction).

• PC then
automatically
increments to ‘02h’
(by design).

Introduction to Computational Thinking 47


An Illustrative Example (Cont’d)

Decode 1
CU decodes the content
IR:

• ‘3’ and ‘A’ Load register


A (for this specific
example)

• ‘40’  with content of


memory location 40h

Introduction to Computational Thinking 48


An Illustrative Example (Cont’d)

Execute 1
CU executes the
instruction:

• Load register A with


content of memory location
40h.

Introduction to Computational Thinking 49


An Illustrative Example (Cont’d)

Fetch 2
• Content location 02h
and 03h are loaded
into IR.

• PC increment to ‘04h’.

Introduction to Computational Thinking 50


An Illustrative Example (Cont’d)

Decode 2
CU decodes the content
IR:

• ‘3’ and ‘B’ Load register


B (for this specific
example)

• ‘41’  with content of


memory location 41h

Introduction to Computational Thinking 51


An Illustrative Example (Cont’d)

Execute 2
CU executes the
instruction:

• Load register B with


content of memory location
41h.

Introduction to Computational Thinking 52


An Illustrative Example (Cont’d)

Fetch 3
• Content of location
04h and 05h are
loaded to IR.

• PC increments to
‘06h’.

Introduction to Computational Thinking 53


An Illustrative Example (Cont’d)

Decode 3
CU decodes the content
IR:

• ‘1C’ add and save result


in Register C

• ‘AB’  Register A and


Register B

Introduction to Computational Thinking 54


An Illustrative Example (Cont’d)

Execute 3
CU executes the
instruction:

• Use ALU to add Register A


and B, and save the result
in Register C.

Introduction to Computational Thinking 55


An Illustrative Example (Cont’d)

Fetch 4
• Content of location
06h and 07h are
loaded to IR.

• PC increments to
‘08h’.

56
Introduction to Computational Thinking
An Illustrative Example (Cont’d)

Decode 4
CU decodes the content
IR:

• ‘2C’ store content of


Register C

• ‘43’  memory location


43h

Introduction to Computational Thinking 57


An Illustrative Example (Cont’d)

Execute 4
CU executes the
instruction:

• Store content Register C in


memory location 43h.

Introduction to Computational Thinking 58


Summary

CPU System bus is used to connect Memory


The main functional REG
external devices, such as memory
ALU and I/O devices, to the functional MEM
units in a CPU
REG units within the CPU. MEM
consist of Control .
Unit (CU), the REG .
Arithmetic/ Logic MEM
CU : System Bus MEM
Unit (ALU) and
Register Array. REG

Instruction Register I/O Devices


Program Counter
keyboard monitor
Execution of a program is performed
• with machine instructions encoded in binary format
• through the Fetch-Decode-Execute cycles by the CPU of a microprocessor

Introduction to Computational Thinking 59

You might also like