5 Computer Architecture and Organization
5 Computer Architecture and Organization
(CSE2003)
05/03/2025 1
Contents
2
05/03/2025 2
Session Objectives
3
05/03/2025 3
4 Understanding the Instruction Execution
05/03/2025 4
5
1. It is a type of memory located inside the CPU. Can hold single piece of data and that Data is
useful for both control functions and data processing itself.
2. Registers name of CPU.
3. The operations on the data in registers are called……….
4. The basic operations like add, subtract are implemented in computer using ……….
05/03/2025 5
Answers: 3. The operations on the data in registers are
5 Register
1. called register operations or register-
based operations.
2. Registers name of CPU.
4. The basic operations like add, subtract are
Program Counter (PC)
Accumulator (AC) implemented in computer using
General Purpose Registers (GPRs) Arithmetic and Logic Unit (ALU).
Data Register (DR)
Instruction Register (IR)
Status Register / Flag Register
Stack Pointer (SP)
Control Registers
Index Registers
Memory Address Register (MAR)
Memory Buffer Register (MBR)
Memory Data Register (MDR)
Instruction Pointer (IP)
Interrupt Register
Debug Registers
05/03/2025 6
Locality of reference.
6
Locality of reference refers to the tendency of a program to access a relatively small portion of its
address space at any given time. It is a fundamental concept in computer architecture, specifically
in memory management and optimization, because it helps improve the performance of systems,
particularly in terms of cache utilization and virtual memory.
1. Temporal Locality
Definition: If a particular memory location (or data) was accessed recently, it is likely to be
accessed again in the near future.
Example: In a loop, where a variable is repeatedly accessed multiple times (e.g., accessing an
array element inside a loop).
Impact: Temporal locality is exploited by keeping recently accessed data in faster memory (like a
CPU cache), so that the next access can be served quickly without needing to go back to slower
main memory.
05/03/2025 7
Locality of reference.
6
Example:
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int sum = 0;
for (int i = 0; i < 10; i++)
{
sum += arr[i]; // Repeated access to arr[i], An example of temporal locality.
}
The comment mentioning “repeated access to arr[i]” is a valid observation of temporal locality, as
the same memory location (arr[i]) is being accessed repeatedly inside the loop.
2. Spatial Locality
Definition: If a memory location is accessed, nearby memory locations are likely to be accessed
soon.
Example: Accessing array elements in sequential order or traversing through elements in a matrix.
Impact: Spatial locality is exploited by preloading adjacent memory blocks into cache or
prefetching nearby data into memory before it is needed.
05/03/2025 8
Locality of reference.
6
Example:
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int sum = 0;
for (int i = 0; i < 10; i++)
{
sum += arr[i]; //Accessing adjacent elements in the array, An example of spatial locality.
}
The comment mentioning “accessing adjacent elements in the array arr[i]” is a valid observation of
spatial locality, as the adjacent memory locations (arr[i]) are being accessed repeatedly inside the
loop.
05/03/2025 9
Locality of reference.
6
3. Importance of Locality of Reference
Improved Performance:
When programs exhibit good locality of reference, fewer memory accesses are required, reducing
the time spent fetching data from slower storage (like main memory or disk).
Prefetching:
The CPU can use locality to predict and preload data into cache before it is needed, minimizing
waiting times.
05/03/2025 10
Difference between Von Neumann and Harvard
7 Architecture
In the Harvard architecture (used by most In Von Neumann architecture all memory
PIC microcontrollers), program code space is on the same bus and instruction and
(instructions) and data are on separate buses data use the same bus.
and this allows the program code and data to
be fetched simultaneously, resulting in an
improved performance.
It improves the speed of the processor
operation because data and addresses do
not have to share the same bus lines. The
reduced size of the instruction set also
speeds up decoding and the short data path
length in a single chip design reduces data
transmission time.
05/03/2025 11
Performance and Speed
Performance (X) = 1
Execution (X)
Performance (X) Execution (Y)
= = n
Performance (Y)
Execution (X)
05/03/2025 12
Measuring Time
Execution time is the amount of time taken by the program to execute.
05/03/2025 13
Measuring Time
1. elapsed time based on a normal clock.
Definition: Elapsed time is the total time it takes from the start to the end of the program's execution,
as measured by a real-world clock (like the clock on the wall).
What it includes:
CPU execution time: The actual time the CPU spends processing the program.
I/O time: Time waiting for input/output operations (disk read/write, network communication, etc.).
System time: Time spent by the operating system managing processes and switching between tasks.
Usefulness: Elapsed time is useful when you want to measure the overall user experience. For
example, if you're timing how long it takes for a web page to load from the user’s perspective, you’re
measuring elapsed time. It includes everything, from the CPU's time to waiting for data to be fetched
from a server.
Example: If you start a program at 10:00 AM and it finishes at 10:03 AM, the elapsed time is 3
minutes.
05/03/2025 14
Measuring Time
2. CPU time is the time spent on executing the program.
Definition: CPU time refers to the time spent by the CPU actually executing the instructions of the
program. It excludes the time spent waiting for I/O operations (like disk access or waiting for user
input) and other system-level processes.
What it includes:
Time spent executing instructions directly related to the program's computation.
It does not include the time spent waiting for the operating system to manage tasks,
waiting for data to be read from the disk, or waiting for user input.
Usefulness: CPU time is a more focused metric, especially when evaluating the efficiency of a
program's algorithm or computational workload. It provides insight into how much time the CPU
spends on actual computation, excluding external delays like I/O or system management overhead.
Example: If the program runs for 3 minutes (elapsed time) but spends 1 minute waiting for a file to
be loaded, the CPU time might only be 2 minutes.
05/03/2025 17
Execution Time
CPU time for this program I/O waiting & other programs
Example: (UNIX)
11.099s 8.659s 10:43.67
(user) (system) (elapsed)
user (direct) system (time in OS)
(seconds) (seconds) (min: secs)
CPU time = 3.0% of elapsed time.
05/03/2025 18
Performance of Processor
13
05/03/2025 19
Performance of Processor
13
05/03/2025 20