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

Lecture 4 - Computer Architecture

Uploaded by

muizzk4321
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture 4 - Computer Architecture

Uploaded by

muizzk4321
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 76

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
Computer Architecture
Q.2 What is computer architecture? Explain components of computer
architecture.
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
2-
Architecture
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
Q.3 Explain CPU with its main components.
CPU
• CPU stands for Central Processing Unit
• Considered as brain of computer
• Performs different operations on the data according to given
instructions
• Manages other operations of computer
• CPU of personal computer is also called microprocessor
• It’s a Single chip
• Its located on motherboard
• 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
Q.4 What is the main memory? Describe its structure. How data is accessed in
main memory?
Memory Unit
• Memory, stores 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
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
RAM
• 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 (Assignment)
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
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)
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
ROM (cont…)
• 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 (Assignment )
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 • User  read & write
and programs (at manufacturing data/programs (at any time
time) during data processing)
• Small storage capacity • Large storage capacity
• Data written  using special • Data written  using electrical
devices & ultraviolet rays devices
Computer Bus
Q.9 What is a computer Bus? Explain its basic types.
Computer Bus
• Different components of computer are interconnected by using a set of
parallel lines or conducting wires
• Computer Bus is a 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
• From input device to memory
• From memory to output device or storage device or between memory and processor
Computer Bus
• Capacity of bus depends upon number of data lines
• For example: bus with 16-lines can carry 16-bits at a time
• Bus Width is defined as an amount of data (or a number of bits) that
a Bus can carry at one time
• For example: bus with 32 lines can transfer 32 bits (or 4 bytes) at a time
• If a bus can handle more bits, it means that the speed of transferring
data is faster.
Types of Buses
(1) System Buses
• Connects main components of computer
• such as CPU & main memory on motherboard
• System Buses are 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 devices via expansion bus & system bus
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, transfers 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 are connected through address bus
• Each component is assigned unique ID to address of that component
• When a computer component needs to communicate
• uses address bus to specify address of that component
Address Bus
• Suppose  CPU needs to read data from memory
• CPU 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 is from 16 to 32 bits
• 32-bit address bus  address 232 (4,294,967,296 i.e. 4GB) memory locations
Types of System Bus
3. Control Bus
• CPU sends control signals to different components or devices
• Control signal includes 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
Control Bus
• 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 it means its 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
• Using Control bus, "memory read" command is send to
main memory
• Using Address bus  CPU places address of memory
location
• Address carried to memory
• Data from requested memory location is fetched
• Than 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
Q.14 Describe the function of the I/O Unit of the computer system.
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.e., I/O unit is
introduced
I/O Unit
• I/O unit control different I/O devices
• I/O unit works as an interface between CPU & I/O devices
• Performs all I/O operations or tasks without direct involvement of
CPU
Ways of transferring data from peripheral
devices into computer
1) Interrupts
• Signal sent by CPU to I/O device (or sent by I/O device to CPU)
• CPU issues command to I/O device for I/O operation
• When device gets ready and generates an interrupt signal to processor
• CPU on receiving interrupt signal, suspends all other processing & performs I/O
operation

Pros:
Requires no additional hardware
Easy to implement
Cons :
Processor suspends all other processing
Reduces overall performance of computer system
Ways of transferring data from peripheral
devices into computer
2) DMA
• DMA stands for Direct Memory Access
• DMA controller is a 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
Pros
• Processor does not have to wait for completion of I/O operation
• Performance increased
Cons
• More complex & more hardware needed to implement
CPU Registers
Q.16 What are CPU registers? Describe the special-purpose registers.
Q.17 Explain different general-purpose registers (GPR).
Q.18 Explain the purposes of different Segment / Address registers.
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 is 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)
• The Program Counter keeps track of the memory address of the next
instruction to be fetched and executed.
• When instruction fetched the value of PC incremented

2. Instruction Register (IR)


• The Instruction Register holds the actual instruction that is currently being
executed by the CPU
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 that is 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 is 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
Segment Registers
• Segment  A block of memory
• Segment Registers  store addresses of memory blocks that are being
currently used by CPU
• CS (Code Segment)
• Holds base location of all executable instructions (code) of program
• DS (Data Segment)
• Used to store base location of memory variables
• ES (Extra Segment)
• Used as an additional base location for memory variables
• SS (Stack Segment)
• Used to store base location of current program stack
Instruction Set
Q.19 What is instruction set? Explain different types of instructions executed by
CPU to perform various operations.
Instruction Set
• Instruction set is a set of all instructions that a CPU can execute
• Different types of CPUs has 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 is provided by CPU
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 I/O instructions 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
Q.20 What is instruction format? Describe various instruction formats.
Instruction Format
• Instruction is a statement in machine code that tells computer to do something
• Instruction code format for general-purpose computer is 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.). Example: In the instruction ADD R1, R2, R3, the opcode would
represent the addition operation.
• Addresses of operands  indicates addresses of operands in memory
• Operands participate in the operation. The addresses of these operands indicate where
the data is located (e.g., in registers or memory).
• Purpose: These addresses guide the CPU to the locations where it should fetch the data
required for the operation.
• Example: In the instruction ADD R1, R2, R3, the addresses of the operands would be the
locations of the data in registers R2 and R3.
Fetch - Decode - Execute
Cycle
Q.21 Explain the Fetch - Decode - Execute cycle of CPU.
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


Fetch - Decode - Execute Cycle
• Fetch:
• Function: The CPU fetches the next instruction from the memory.
The memory address of the next instruction is provided by the
Program Counter (PC).
• Steps:
• The value in the Program Counter is used to address the memory.
• The instruction at that memory location is fetched and loaded into
the Instruction Register (IR).
• The Program Counter is then incremented to point to the next
instruction.
• Decode:
• Function: The CPU decodes the instruction to understand what operation
needs to be performed.
• Steps:
• The opcode (operation code) of the instruction is extracted from the
Instruction Register.
• The CPU interprets the opcode to determine the type of operation (e.g.,
addition, subtraction, load data from memory, etc.).
• Additional information, such as memory addresses or operands, may also be
extracted during the decode phase.
• Execute:
• Function: The CPU performs the actual operation or instructions specified by
the opcode.

• Steps:
• The ALU (Arithmetic Logic Unit) carries out arithmetic or logic operations.
• Data may be moved between registers or between the CPU and memory.
• Results of the operation are stored back in registers or memory as needed.
• Any necessary flags or status registers may be updated based on the outcome
of the operation.
Port
Q.22 What is a port? Explain different types of ports.
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
END
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
Programming Languages
Q.25 What are programming languages? Explain low-level and high-level
languages.
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
Q.27 What is a language translator? Explain its different types.
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 computer
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
Compiler Interpreter
• Translates as a whole • Translates statement-by-statement
• Creates an object file • Does not create an object file
• Fast program execution • Slow program execution
• Translated only once • Translated each time to run the
• Not easier to correct errors program
• Easier to correct errors
Primary Memory Secondary Memory
• Temporary memory • Permanent memory
• Use to store during data • Use to store permanently for later
processing use
• Volatile memory • Non-volatile memory
• Smaller storage capacity than • Larger storage capacity than primary
secondary memory memory
• High data accessing speed • Slow data accessing speed
• Directly accessed by CPU • Not directly accessed by CPU

You might also like