COMPUTER SCIENCE
11
Chapter 5
Computer Architecture
Contents
Computer Architecture
CPU
Memory Unit
Computer Bus
I/O Unit
CPU Registers
Instruction Set
Instruction Format
Fetch - Decode - Execute Cycle
Port
Operating System
Programming Languages
Language Translator
Von Neumann Design
1951 proposed design of a stored-program computer
By Von Neumann & his team
Design a sequence of instructions (called a program) & data are stored in memory
Computer reads instructions one by one
executes these instructions to perform different operations on data
Very simple design & general-purpose
Modern digital computers based on Von Neumann design
Computer Architecture
Components of computer
each component performs a specific function
Components of computer communicate with one another
Computer architecture Way in which various components of computer are connected
Components of Computer Architecture
1- CPU
CPU Central Processing Unit, Processor
Considered as brain of computer
Processes (or manipulates) data according to given instructions and converts it into useful
information
Components of CPU
Control Unit (CU)
Acts as a supervisor of computer
Controls all parts of computer & coordinates all activities of computer
Fetches instructions & data from memory unit
Decodes & executes instructions one by one
Arithmetic & Logic Unit (ALU)
Performs all arithmetic & logical operations on data
Components of Computer Architecture
2- Main Memory
Memory Used to store data and instructions
CPU loads data & instructions in main memory
Reads data & instructions from main memory
Process data according to given instructions
Data and results of calculations stored in main memory
Working area of computer (computer cannot work without having main memory)
3- I/O Unit
Controls communication between processor & peripheral devices (i.e. I/O devices)
Peripheral devices keyboard, monitor, printer, & disk drives
Controls different I/O devices connected to computer system
4- Bus Interconnection
Bus electrical path through which data, instructions, or control signals flow from one component of
computer to another
Communication channel on motherboard
Connects different components of computer (such as CPU, main memory, and I/O units)
CPU
CPU Central Processing Unit, Processor
Considered as brain of computer
Performs different operations on the data according to given instructions
Manages other operations of computer
CPU of personal computer microprocessor
Single chip
Located on motherboard
Other components connected to it through Bus interconnection
CPU sends & receives data to/from different components of computer through Bus
interconnection
Components of CPU
1. Control Unit
Acts as a supervisor of computer
Controls all parts of computer & coordinates all activities of computer
Example: receives data & instructions from input device and stores them in main memory.
Also controls execution of instructions given to computer
Fetches instructions & data from memory unit
Decodes & executes instructions one by one
2. Arithmetic & Logic Unit (ALU)
Performs arithmetic & logical operations on data
Arithmetic operations ALU performs addition, subtraction, multiplication, & division
Logical operations ALU compares numerical data as well as alphabetic data
For example: checks whether first number is greater than second, less than second or equal to second, etc.
Memory Unit
Memory store data & instructions
Personal computer contains a main memory
CPU loads data & instructions in main memory to process data
CPU reads data & instructions from main memory & processes data according to given
instructions
Data & results of calculations are also stored in main memory
Working area of computer
computer cannot work without having main memory
Two types of memories
RAM
ROM
Structure of Main Memory
Built in form of a chip
chip made of semiconductor material
Main memory of computer consists of thousands or millions
of cells
Each cell store a bit (Binary digit)
bit represents 0 or 1
Cells logically organized into a group of 8 bits byte
Byte in memory unique number assigned address of that byte
Accessing Data in Main Memory
Main memory collection of bytes arranged in an order
CPU access any byte by specifying its address
Different bytes accessed directly or randomly
Accessing any part of memory takes an equal amount of time
Very fast to access data as compared to other storage devices (magnetic and optical disks)
because; main memory does not involve any mechanical movement in accessing data
RAM
RAM Random Access Memory
Because; data accessed directly
Used for storage of active programs & data
Processor directly write & read information (data & instructions) to/from RAM
read/write memory
Processor write information (data & instructions) to RAM
Processor read information from RAM
Temporarily storage, primary memory
volatile memory
data and programs lost when power is turned off
Information must be saved on storage devices for later use
Storage capacity measured in bytes
PCs RAM size 4GB or more
More RAM size computer can use a powerful program with a large size
Improves data processing speed
Types of RAM
1. DRAM
DRAM Dynamic Random Access Memory
Used in most of the computers
To maintain data in DRAM refreshed with electric charge again and again
otherwise, data lost
During refreshing process CPU has to wait (write/read data to/from DRAM)
Slow memory
2. SRAM
SRAM Static Random Access Memory
Does not have to be refreshed with electric charge again and again
Faster than DRAM
because CPU does not have to wait
Utilize less power than DRAM
More expensive than DRAM chip
SRAM technology used to build a very fast memory cache memory
Cache Memory
Processor obtains data & instructions from RAM during data processing
Often obtains same data or instructions again and again
a lot of time wasted
Performance affected
Cache memory very small but very fast memory than RAM
Used to improve performance of processor
Build-in with CPU
Separate chips on motherboard (located between RAM and CPU)
Stores frequently used instructions & data
When CPU needs specific data or program instruction
quickly obtains from cache memory
Speeds up the working of CPU
If required data & instructions not found processor loads them
into RAM from disk (i.e. hard disk)
loads/stores a copy in cache memory
ROM
ROM Read Only Memory
Data and instructions stored by manufacturer at time of ROM manufacturing
cannot be changed afterward
Data or instructions can only be read but cannot be written
That is why, Read Only Memory
Stores permanently
non-volatile memory
When power turned off instructions not lost
Contains instructions help booting process
When computer is switched on instructions in ROM automatically activated
prepare the computer for use
Types of ROM
1. PROM
PROM Programmable Read Only Memory
Initially blank
User or manufacturer write data or programs on it by using special devices
Once program or data is written cannot be changed
If error in writing program or data cannot be removed
PROM chip becomes unusable
2. EPROM
EPROM Erasable Programmable Read Only Memory
Initially blank; user or manufacturer write a program or data by using special devices
Program or data can be removed (erased) by using special devices and ultraviolet rays
program or data can be changed & new data can be added
When EPROM is in use, only read contents
3. EEPROM
EEPROM Electrically Erasable Programmable Read Only Memory
User can write or change instructions or information with the help of electrical devices
ROM RAM
Read-only memory Read & write memory
Permanent memory Temporary memory
Non-volatile memory Volatile memory
Manufacturer only write data and User read & write data/programs (at
programs (at manufacturing time) any time during data processing)
Small storage capacity Large storage capacity
Data written using special devices & Data written using electrical devices
ultraviolet rays
Computer Bus
Different components of computer interconnected by using a set of parallel lines or conducting
wires
Computer Bus set of electrical paths through which computer (CPU) sends & receives data &
instructions (and also sends command signals) to/from different components of computer
Backbone of computer
Without bus Computer cannot perform any function
Various devices or components communicate through buses
Example: buses transfer data
input device memory
memory output device or storage device or between memory and processor
Capacity of bus depends upon number of data lines
For example: bus with 16-lines carry 16-bits at a time
Bus Width amount of data (or a number of bits) that a Bus can carry at one time
For example: bus with 32 lines transfer 32 bits (or 4 bytes) at a time
Larger number of bits handled by bus faster data transfer rate
Types of Buses
(1) System Buses
Connects main components of computer
such as CPU & main memory on motherboard
System Buses part of motherboard
Normally 70 – 100 lines
Types of System Bus
Data Bus
Address Bus
Control Bus
(2) Expansion Buses
Connect CPU (processor) to peripheral devices
Peripheral devices: keyboard, mouse, modem, printer, etc.
Processor communicates with peripheral via expansion bus & system bus
Width of expansion buses from 16 to 64 bits
Types of System Bus
1. Data Bus
Transfer data (and instructions) between different components
Connects CPU, memory unit, and other hardware devices on motherboard
bi-directional
Data sent & received through this electrical path
For example: CPU write & read data to/ from main memory through a data bus
Consists of 8, 16, 32, or 64 parallel lines
Data Bus of 64-line transfer 64-bits (or 8 bytes) of data at a time
Number of lines affects speed of data transfer
Types of System Bus
2. Address Bus
Carry address information or memory locations
Unidirectional
information flows only in one direction
CPU can only send address information & cannot receive any information
Components connected through address bus
Each component assigned unique ID address of that component
When a computer component needs to communicate
uses address bus to specify address of that component
Suppose CPU needs to read data from memory
places address of that memory location on address bus
address is carried to memory
Data from requested memory location fetched
placed on data bus
CPU reads data from data bus
Width of address bus from 16 to 32 bits
Types of System Bus
3. Control Bus
CPU sends control signals to different components or devices
Control signal timing information & command signal
Timing information time for which device or component can use data & address bus
Command signal specifies the type of operation that is to be performed
CPU (control unit) controls functioning of components through control bus
Components & devices input/output devices, main memory, secondary storage devices, etc.
Width of control bus from 8 to 16 bits
Suppose CPU wants to read data from main memory
Control bus send "memory read" command to main memory
Also transmit other control signals like ACKS (Acknowledgement signals)
When CPU sends command to main memory writing data
memory sends back acknowledgment signal to CPU after writing data successfully
CPU Commands CPU operations
Memory Write
Used to write data to a specified location in main memory
Memory Read
Used to read data from a specified location in main memory
I/O Write
Used to write data to an output device
I/O Read
Used to read data from an input device
Bus Request
Used to request for taking control of Bus
so that requesting device can use it to transmit data
Bus Grant
Used by Bus controller to indicate grant of the Bus to a device
Data Communication: CPU Memory
Suppose CPU wants to read data from main memory
Control bus "memory read" command send to main memory
Address bus CPU places address of memory location
Address carried to memory
Data from requested memory location fetched
placed on data bus
CPU reads data from data bus
If Number of components connected to system bus increase, then
More components try to use System Bus at same time
Slow down computer
Because; components have to wait longer to get access to Bus
Solution of Problem:
Only major components are connected
Remaining components are connected to another external Bus Expansion Bus
Expansion Bus connected to System Bus
I/O Unit
Input/output devices
keyboard, mouse, scanner, monitor, printer, microphone, video camera, etc.
Different functions
Different data transfer rate
Support different formats
Impossible to connect directly to system bus
Difficult for CPU to control directly.
Solution Special hardware component I/O unit
I/O unit control different I/O devices
Only I/O unit connected to Bus
CPU and all other devices are connected to I/O unit
Works as an interface between CPU & I/O devices
Performs all I/O operations or tasks without direct involvement of CPU
Responsible to manage speed difference between processor & I/O devices
Ways of transferring data from peripheral devices into
computer
1) Interrupts
Signal sent by CPU I/O device (or sent by I/O device CPU)
CPU issues command to I/O device for I/O operation
When device gets ready generates an interrupt signal to processor
CPU on receiving interrupt signal suspends all other processing & performs I/O operation
+ Requires no additional hardware
+ Easy to implement
- Processor suspends all other processing
- Reduces overall performance of computer system
Ways of transferring data from peripheral devices into
computer
2) DMA
DMA Direct Memory Access
DMA controller special hardware component
Data transfer takes place without involvement of CPU
CPU sends request to DMA controller to perform I/O
operation
CPU continues to do other tasks
When data transfer completed
DMA controller sends on interrupt signal to CPU
CPU involved only at beginning & end of data transfer
+ Processor does not have to wait for completion of I/O
operation
+ Performance increased
- More complex & more hardware needed to implement
CPU Registers
Registers CPU contains small, high-speed storage locations (areas)
Used during program execution
Temporarily hold instructions, data, or intermediate results of calculations
Different types of registers used for a specific purpose
Size of registers 1, 2, 4, or 8 bytes
Large register increases performance of CPU
Example: computer having 32-bit (4-bytes) registers CPU can process four bytes of data at a time
Types of Registers
Special-purpose registers
General-purpose registers
Segment registers
Special Purpose Registers
Perform specific functions (special functions) during program execution
1. Program Counter (PC)
Controls sequence in which instructions are fetched from
memory
Holds (stores) the address of next instruction to be fetched for
execution
When instruction fetched value of PC incremented
register always points or holds address of next instruction
Instruction Pointer Register
2. Instruction Register (IR)
Stores recently fetched instruction from memory
Control unit takes this instruction
Special Purpose Registers
3. Memory Address Register (MAR)
Holds address of memory where CPU wants to read/write
When CPU wants to read/write
places address of required memory location in the MAR
4. Memory Buffer Register (MBR)
Store data coming from memory & going to memory
5. Stack Pointer
Stack set of memory blocks (data stored and retrieved in
order)
Order Last In, First Out (LIFO)
Stack pointer register used to manage stacks in memory
For example: undo & redo operations in different application software
General-Purpose Registers
Store data (operands), addresses of data and intermediate results of operations
Used for arithmetic & logical operations, data movement
Part of ALU
1. Accumulator Register (AX)
Used for arithmetic and other data operations
2. Base Register (BX)
Used during arithmetic, logic, and data movement operations
Stores memory addresses of data
3. Counter Register (CX)
Used for counting purposes
Acts as a counter for looping
4. Data Register (DX)
Used with Accumulator register for division & multiplication operations
Also used in input/output operations
General-Purpose Registers
General-purpose registers EAX, EBX, ECX, and EDX
Divided into a higher & lower byte
Lower byte registers AL, BL, CL, and DL
Higher byte registers AH, BH, CH, and DH
A Accumulator
B Base
C Count
D Data
H Higher
L Lower
Size lower byte & higher byte 1 byte (8 bits)
Size of AX, BX, CX, and DX 2 bytes (16 bits)
Size of EAX, EBX, ECX, and EDX 4 bytes (32 bits)
Modern processors use 4 bytes registers EAX, EBX, ECX, and EDX
Segment Registers
Segment A block of memory
Segment Registers store addresses of memory blocks that are being currently used by CPU,
Address registers
Four segment registers CS, DS, ES, & SS
Size 2-bytes
Used with IP register or with two index registers DI & SI to address various areas or blocks of memory
CS (Code Segment)
Holds base location of all executable instructions (code) of program
Used along with IP register to fetch instruction
DS (Data Segment)
Used to store base location of memory variables
Used along with DI or SI register to refer to data
ES (Extra Segment)
Used as an additional base location for memory variables
SS (Stack Segment)
Instruction Set
Instruction set A set of all instructions that a CPU can execute
Different types of CPUs different instruction set
Modern CPU can execute 80 to 120 instructions
Types of Instructions
Data Transfer Instructions
Arithmetic and Logical Instructions
I/O Instructions
Control Transfer Instructions
Types of Instructions
1- Data Transfer Instructions
Used to transfer data from one unit of computer to another during program execution
Different instructions for transfer of data provided by CPU
Programmer use to transfer data from RAM to CPU registers and back to RAM or to output
devices etc.
2- Arithmetic and Logical Instructions
Arithmetic Instructions perform arithmetic operations
Arithmetic operations addition, subtraction, multiplication, and division
Executed by ALU
Logical Instructions perform logical operations
Logical operation comparing two data values
Executed by the ALU
Types of Instructions
3- I/O Instructions
Used for writing & reading data to peripheral devices
Peripheral devices keyboard, monitor, and disks, etc.
programmer use to perform I/O operations
4- Control Transfer Instructions
Used to transfer execution control from one part of program to another during program execution
Used to execute or ignore a set of instructions after testing a condition
Used to execute a set of instructions repeatedly for a specified number of times
Examples: JUMP & JUMPZ (Jump if zero)
Instruction Format
Instruction statement in machine code that tells computer to do something
Consists of a group of bits that is logically divided into different parts
Each part performs specific action
Structure of instruction Instruction format
Variety of instruction code formats
Control unit responsible to interpret instruction code
provides necessary control function needed to execute instruction
Instruction code format for general-purpose computer 16-bits
General format of instruction Opcode [Addresses of Operands]
Parts of Instruction code format
Opcode (operation code) indicates type of action or operation (addition, multiplication, subtraction,
division, etc.). It takes 4 bits
Addresses of operands indicates addresses of operands in memory
Various Instruction Code Formats
Different instructions different addresses
Instruction divided according to addresses used
1- Zero-Address Instruction Format
No address field
Stack-organized computer instructions like ADD & MUL
instructions like PUSH & POP need address field to specify operand (stack)
For example: ADD instruction used without specifying any memory address
Instruction takes values from stack, adds them, and returns result to stack
2- One-Address Instruction Format
Only one address field
Uses accumulator register for all data calculations or manipulations
However, second register is required for multiplication & division
Various Instruction Code Formats
3- Two-Address Instruction Format
Uses two address fields
Each specify either a register or a memory address
Most common format
Examples: MOV, ADD, CMP, and BIS
4- Three-Address Instruction Format
Uses three address fields
Each specify either a register or a memory address
+ Takes less execution time
- Binary-coded instructions require too many bits to specify three addresses
Fetch - Decode - Execute Cycle
fetch- decode- execute cycle (FDX), instruction cycle Process by which
CPU fetches a program instruction from memory
decodes instruction
executes it
CPU works by following FDX cycle to execute all instructions
When program is to be executed
Instructions & data loaded from disk into main memory
Address of first instruction copied into PC register
Control given to CPU for execution
Fetch - Decode - Execute Cycle
1) Fetch Instruction
CPU fetches instruction & data from memory by
Copies memory address from PC MAR
Sends memory read command to main memory
Copies data from main memory MBR & instruction IR (instruction register)
Value of PC incremented (point to next instruction)
2) Decode Instruction
CPU decodes instruction by analyzing opcode of instruction
Also reads values of operands specified in instruction
Actually, necessary circuits are activated that are required to execute instruction
3) Execute Instruction
CPU executes instruction by using activated circuits
CPU generates control signals needed for execution & sends these signals to relevant units (perform action)
For example:
control unit passes data & decoded instruction to ALU
ALU performs mathematical or logic operations on data according to instruction code
Results are written in registers & memory
Port
Peripheral devices connected to system unit through a special device
Port
Port interface or connecting point
Provide a standard way of communication between computer and its
peripheral devices
Example: keyboard, mouse, printer, monitor, & modem connected
with computer by plugging their connectors into ports
Computer or mobile device different types of ports
Example: desktop personal computer different ports on its front and
back
Types of Port
i) Serial Port
Transmits one bit at a time
communication (COM) port
Slow data transmission
Data transmission rate 115 Kbps or more
Serial port mouse, keyboard, and modem are connected
do not require fast data transmission
Not used today
Types of Port
ii) Parallel Port
Transmits many bits at a time
Faster data transmission than serial port
Data transmission rate up to 12 Mbps or more
Parallel port printer and scanner connected
Line Printer Ports (LPT)
Not used in modern computers
Parallel and serial ports replaced with USB ports
Types of Port
iii) USB Port
USB Universal Serial Bus
Most popular standard port used in PCs
Single connector allows up to 127 peripheral devices to be connected
Examples: keyboard, mouse, printer, scanner, digital camera, speakers, card reader,
smartphone, USB flash drives, & external hard disk
USB ports in personal computers typically 6 to 8 either on front or back
Also be used as a power supply for different devices
such as smartphones & tablets
Operating System
Q.23 What is operating system? Name some important operating systems.
Operating System
A set of system programs that controls & coordinates overall operations of a computer system
(or mobile device)
Computer needs an operating system to do work
Computer cannot operate without OS
Without OS, computer is like a car with no fuel
OS must be installed on computer to perform different tasks
When computer is turned on, OS loaded into main memory from disk
Performs various functions residing in main memory
Tasks of OS
Provides user-interface
Accepts input from input devices
Sends output to output devices
Manages the application programs in memory
Organizes data on storage devices
Performs memory management tasks
Operating System
Controls overall hardware to perform various operations
Provides most common functions needed by users & programmers
Users & programmers request hardware through OS
OS provides an interface to users & programmers
Important Operating Systems
Microsoft Windows
UNIX
Linux
Mac OS
Solaris
Functions of Operating System
1. Booting
OS starts computer and makes it ready to work
Process of starting or restarting a computer booting
2. Manage Hardware Resources
Different applications (or programs) try to use various hardware resources at same time
OS is responsible for allocating & managing various resources for different applications
3. Memory Management
Data & program must be loaded into main memory for execution
Different programs & data can be loaded at the same time
OS manages and allocates memory to different programs
OS carefully monitors contents of memory
When program terminates its execution OS de-allocates (clears) memory area and its related data
4. Loading and Executing Programs
Program loaded into main memory for execution
OS provides facility for loading program into memory and for starting its execution
Functions of Operating System
5. Data Security
OS provides facility to protect important data against illegal access and modification (unauthorized access).
6. Providing User-Interface
OS provides an interface between user & computer
User interacts with computer through OS
User requests computer through OS to perform specific task
Command-line User Interface
provides a prompt line on computer screen
User communicates by typing commands through keyboard
Difficult interface
Example: MS-DOS operating system
Graphical User Interface (GUI)
provides graphical images on computer screen
Images icons or command buttons
Example: application programs, commands, disk drives, files, etc. in form of icons
User communicates by clicking icons with a pointing device (such as mouse)
GUI easy to interact
Example: Microsoft Windows
Programming Languages
Provides way of communication between user & computer
Computer program written in programming language
Various programming languages
Example:
programming languages for writing business programs
programming languages for writing scientific programs
Syntax set of rules of a specific programming language to write a computer program
Program instructions are written according to these rules
Types of Programming language
Low-level languages
High-level languages
Types of Programming Languages
1- Low-Level Languages
Near to machine language (0s and 1s)
Difficult to learn and use
because instructions are written in binary form and symbolic form
Examples: machine language & assembly language
(i) Machine Language
Instructions are written in binary form (in form of 1s and 0s)
Fundamental language of computer
Computer only understands machine language
No need to translate
because; already in machine code i.e. binary form
(ii) Assembly Language
Easier to learn and use than machine language
Instructions are written by using short names or symbols mnemonics
Example: ADD for addition, MUL for multiplication, and SUB for subtraction
Types of Programming Languages
2- High-Level Languages
Near to human languages
Easy to learn and use
Instructions written in English like words print and input etc.
Language has its own rules or grammar for writing program
Computer cannot understand program written in any high-level language
Must be translated to machine code before running on computer
Language has its own translator program
Examples: BASIC, FORTRAN, C & C++, Java, Pascal, Visual Basic, and COBOL.
Source Code
Program written in any high-level programming language or
assembly language
Cannot be executed directly by computer
Must be converted into machine code before running it on computer
Object Code
Computer understands only machine code
Source code high-level languages and assembly language code
Must be translated into machine code before running it on computer
Translated program into machine code object code
Language Translator
System software that translates source code into machine code
(object code)
language processor
Every programming language (except machine language) has
its own language translator
Computer only understands instructions in machine code (i.e.
0’s and 1’s)
Difficult to write program directly in machine code
Mostly programs are written in high-level languages
such as C/C++, Java, and BASIC
Must be translated into machine code before running on
Language Translator
1- Compiler
Translates source code into machine code (object code) as a whole
Examples: C and C++ translators
Compiler analyzes source code & checks errors
If no error translates source code into object code (machine code)
If error specifies errors and does not translate
Language Translator
2- Interpreter
Translates & executes statements of a source code one by one
Translates one statement & executes it immediately
before translating next statement
Process continued up to end of the program
If error terminates translating process at that statement
Also displays an error message
Example: GW-BASIC translator
+ Easier to detect & correct errors in source program
- Time-consuming process
- Does not produce object code
- Each time program run source code translated again
- Must have a Interpreter permanently on our computer
3- Assembler
Translates program written in assembly language into machine code
Compiler Interpreter
Translates as a whole Translates statement-by-
Creates an object file statement
Fast Doesnot create an
program
execution object file
Translated Slow program execution
only once
Not Translatedeach time to
easier to correct
errors run the program
Easier to correct errors
Primary Memory Secondary Memory
Temporary memory Permanent memory
Use to store during data Use to store permanently for
processing later use
Volatile memory Non-volatile memory
Smaller storage capacity Larger
storage capacity than
than secondary memory primary memory
Highdata accessing Slow data accessing speed
speed Not directly accessed by
Directly accessed by CPU CPU