1. What is CPU?
• A CPU (Central Processing Unit) is the logic circuitry that responds to and processes
the basic instructions that drive a computer.
• It performs three main tasks:
1. Arithmetic & Logic operations
2. Data transfer between memory and I/O systems
3. Program flow control through simple decisions
Q.1(a) What is microprocessor?
• A microprocessor is a CPU housed on a single silicon chip. microprocessor is a
programmable digital device designed with registers, flip-flops, and timing circuits.
• Microprocessor based PC system consists of:
o CPU core /Microprocessor (Perform 3 main tasks)
o I/O System (Communicates to human and machine0
o Memory system (Stores program & data)
Q. Importance of the Microprocessor in a System
• The microprocessor is the brain of modern computer systems.
• It controls and coordinates the memory system and I/O devices.
• It is capable of executing millions or billions of instructions per second, making it the
central element of performance in computers.
• Without it, no meaningful computation or control could occur.
(a) How does a microprocessor work?
1. The microprocessor has a set of internal instructions (its instruction set).
2. Instructions and data are written via input devices and stored in memory.
3. The microprocessor reads one instruction at a time from memory.
4. It matches the instruction with its instruction set and executes the required operation.
5. The result is stored back in memory or sent to an output device (e.g., display, printer).
6. It can also respond to external signals (reset, wait, interrupts) to synchronize with
slower peripherals.
Q. Features of a Microprocessor
• Programmable digital device
• Uses registers, flip-flops, and timing circuits
• Executes instructions sequentially
• Performs:
o Data transfer
o Arithmetic and logic operations
o Program control decisions
• Can communicate with peripheral devices (keyboard, printer, etc.)
Comparison Of Different types:
How many
bits can Register
Type Processing Speed Power Consumption Cost
handle at Size
once
Handles 4 bits
4-bit 4-bit Lowest power (small
(half a byte) at Very low, slowest Lowest
(4004) registers chip, less circuitry)
a time
8-bit Handles 8 bits
8-bit Higher
(8008, (1 byte) at a Faster than 4-bit More than 4-bit
registers than 4-bit
8080) time
16-bit Handles 16 Much faster,
16-bit Higher
(8086, bits (2 bytes) supports larger Higher than 8-bit
registers than 8-bit
80286) at a time memory
32-bit Handles 32 Very fast Highest among these
32-bit
(80386, bits (4 bytes) (multitasking (more transistors, Highest
registers
80486) at a time possible) bigger chip)
✅ Quick Memory Trick:
• Bit = 1
• Nibble = 4
• Byte = 8
• Word = 16
• Double Word = 32
• Quad Word = 64
• Octal Word = 128
KIP (Kilo Instructions per Second)
Means how many thousand instructions a processor can execute in one second.
MIP (Million Instructions per Second)
• Means how many million instructions a processor can execute in one second.
• A measure of processor speed/performance.
Von Neumann model: Basic Memory Architecture:
Draw & explain the microprocessor-based computer system:
1. Microprocessor
• Performs three main tasks:
1. Data transfer (to/from memory & I/O).
2. Arithmetic and logic operations.
3. Program control (decisions, jumps, execution flow).
2. Memory (ROM & DRAM)
• ROM (Read-Only Memory): Stores permanent instructions (e.g., boot programs,
firmware).
• DRAM (Dynamic RAM): Stores temporary data and programs while the computer is
running.
3. I/O Devices (Keyboard & Printer)
• Keyboard (Input Device): Sends user data/instructions to the microprocessor.
• Printer (Output Device): Receives processed data from the microprocessor and
produces output (hard copy).
Buses in Computer System
Definition:
A bus is a common group of wires that connects and transfers data between the components of
a computer system (CPU, memory, and I/O devices).
Types of Buses:
1. Address Bus
o Used to select a memory location or a specific I/O device.
o It carries the address of where data should be read from or written to.
o Unidirectional (data flows only one way – from CPU to memory/I/O).
2. Data Bus
o Transfers the actual data between microprocessor, memory, and I/O devices.
o Bidirectional (data can flow both ways).
3. Control Bus
o Carries control signals to manage operations.
o Helps the CPU decide whether to read/write and whether to access memory or
I/O.
Why are buses needed in computer systems?
• Buses are needed to connect different parts of the computer (CPU, memory, I/O
devices).
• They provide a common communication path so that data, addresses, and control
signals can move efficiently.
• Without buses, each device would need separate wiring to the CPU → making the system
complex and costly.
Control Bus Connections (Briefly):
o Carries control signals to manage operations.
o Helps the CPU decide whether to read/write and whether to access memory or
I/O.
• MRDC (Memory Read Control): CPU reads data from memory.
• MWTC (Memory Write Control): CPU writes data into memory.
• IORC (I/O Read Control): CPU reads data from an input device.
• IOWC (I/O Write Control): CPU sends data to an output device.
Multipurpose Registers
Multipurpose Registers are general-purpose registers used for a variety of functions in the
microprocessor. These registers can be accessed and used in different bit sizes (e.g., 64-bit, 32-
bit, 16-bit, and 8-bit). Below are some examples of multipurpose registers:
1. RAX (Accumulator Register)
o A 64-bit register that can be accessed as:
o Used for instructions like multiplication, division, and adjustment operations.
2. RBX (Base Register)
o Can be accessed as:
o Often holds the offset address of memory locations.
3. RCX (Count Register)
o Used as a general-purpose register and for holding the count in various
operations like loops.
4. RDX (Data Register)
o Used to hold data, especially in multiplication or division instructions.
5. RBP (Base Pointer)
o Points to the memory location for memory data transfers (commonly used in
function calls).
6. RDI (Destination Index Register)
o Primarily used in string operations to point to the destination data.
7. RSI (Source Index Register)
o Used in string operations to point to the source data.
8. R8 to R15 (Extended Registers)
o These are 64-bit registers found in processors with 64-bit extensions like
Pentium 4 and Core2.
o These are general-purpose registers and can be used in 64-bit systems for data
processing.
Special-Purpose Registers
Special-Purpose Registers are registers used to control operations within the microprocessor
or to track the processor’s current state. These include:
1. RIP (Instruction Pointer)
o Points to the next instruction in the memory (code segment).
o Helps the processor keep track of the execution flow.
2. RSP (Stack Pointer)
o Points to the top of the stack in memory.
o Used to store return addresses during function calls and to manage the stack.
3. RFLAGS (Flags Register)
o Indicates the status of the processor and controls its operation.
o Holds flags that reflect the outcome of arithmetic operations (e.g., Zero Flag,
Carry Flag).
4. Segment Registers
o These include:
▪ CS (Code Segment)
▪ DS (Data Segment)
▪ ES (Extra Segment)
▪ SS (Stack Segment)
▪ FS, GS
o These registers help the processor access different segments of memory, such as
code, data, and stack.
9 Active Flags:
6 Conditional Flags :are set/reset by EU on the basis of the results of some arithmetic or
logical operation.
• C (Carry)
o Holds the carry after addition or borrow after subtraction.
o CF is set if an operation results in a carry, else it is reset.
• P (Parity)
o Indicates the parity (even or odd) of a number by counting the 1's in the result.
o PF is set if the result has even parity (even number of 1's).
o PF is reset if the result has odd parity (odd number of 1's).
• A (Auxiliary Carry)
o Holds the carry (half-carry) between bit positions 3 and 4 during addition or
subtraction.
o AF is set when a carry is generated between bits 3 and 4.
• Z (Zero)
o Indicates whether the result of an arithmetic or logical operation is zero.
o ZF is set if the result is zero, otherwise, it's reset.
• S (Sign)
o Represents the sign of the result of an operation.
o SF is set if the most significant bit of the result is 1 (negative), else it is reset
(non-negative).
• O (Overflow)
o Set when overflow occurs in signed numbers (i.e., when the result exceeds the
capacity of the register).
o Indicates an arithmetic overflow.
3 Control Flags: are set/reset with specific instruction put in your program
• T (Trap)
o Enables a trap for debugging, allowing single-step execution.
o When TF is set to 1, the processor goes into single-step mode, generating an
interrupt after each instruction.
• IF (Interrupt Flag)
o Controls whether the interrupt requests are enabled or disabled.
o IF = 1 allows interrupts, and IF = 0 disables interrupts.
• D (Direction)
o Determines whether the DI (destination index) and SI (source index) registers
increment or decrement.
o D = 1 decrements the registers, D = 0 increments them.
Two Index Registers:
1. SI (Source Index):
o Used to point to source data in memory for string operations.
2. DI (Destination Index):
o Used to point to destination data in memory for string operations.
Three Pointer Registers:
1. SP (Stack Pointer):
o Points to the top of the stack in memory.
2. BP (Base Pointer):
o Points to the memory location for memory data transfers
3. IP (Instruction Pointer):
o Holds the address of the next instruction to execute.
Internal Architecture of 8086:
Q.2(a) "All real mode memory addresses are a combination of a segment address and an
offset address." Explain the statement with a suitable example.
Real Mode Operation
Real mode operation allows addressing only the first 1MB of memory space.This first 1MB of
memory is referred to as real memory, conventional memory, or the DOS memory system.
Segments and Offsets : In real mode, memory addresses are composed of two parts:
1. Segment Address: defines the starting address of a 64K-byte memory segment.
2. Offset Address (also called displacement): This selects any location within the 64K-
byte segment.
For example, if the segment address is 1000H and the offset address is 2000H, the physical
memory address is calculated as:
• Physical Address = (Segment Address × 10) + Offset Address = (1000H × 10) + 2000H =
10000H + 2000H = 12000H.
Segment and Offset Addressing allows relocation
The segment-offset addressing scheme makes a program relocatable. A relocatable program
means it can be loaded into any area of memory and executed without modification. This is
because the segment address determines the base location of the segment, while the offset
address specifies a location within that segment. Therefore, a segment can be moved to any
position in memory, and only the segment register needs to be updated to reflect the new
location.
Why is Offset Address called Offset?
The offset address is called an offset because it represents the distance from the beginning of a
memory segment. It's an "offset" added to the starting address (segment address) to access
specific locations within that segment.
Short Note on TPA:
Introduction to Protected Mode Memory Addressing
• Access to Memory: Protected mode allows access to data and programs above the first
1MB of memory, which was the limitation in real mode.
• Segment Registers and Selectors: Unlike real mode where segment registers directly
contain the segment address, in protected mode, the segment register contains a selector.
This selector points to a descriptor in a descriptor table.
Features of Protected Mode
• Multitasking and Memory Protection: Protected mode is primarily used by
multitasking operating systems like Windows. Each running program is assigned its
own memory space, which is protected to prevent it from interfering with other
programs.
• Protection Fault: If a program attempts to access memory it is not allowed to, the
processor generates a protection fault. This triggers an error, ensuring that programs
cannot corrupt or access unauthorized memory.
Selectors and Descriptors in Memory Addressing
• Descriptor: The descriptor is a data structure stored in memory that describes:
o Location: Where the segment starts in memory.
o Length: How much memory the segment occupies.
o Access Rights: What operations (read, write, execute) are allowed on that
segment.
• Selector: The selector, located in the segment register, selects one of 8192 descriptors
from one of two tables of descriptors.
• Descriptor Tables: In protected mode, the segment register points to a descriptor table
containing up to 8192 descriptors. This provides flexibility in addressing memory
segments. There are typically two tables:
o Global Descriptor Table (GDT): Contains global descriptors for system-wide
memory.
o Local Descriptor Table (LDT): Contains local descriptors, which are specific
to a particular program or application.
• Indirect Memory Addressing: In protected mode, the segment register indirectly
selects a memory segment via the descriptor table, as opposed to directly referencing a
memory address like in real mode.
Global vs. Local Descriptors
• Global Descriptors: These descriptors define memory segments that are accessible by
all programs. They are often called system descriptors and provide a system-wide view
of memory.
• Local Descriptors: These are unique to a specific application. Each program or task gets
its own local descriptor table, often called application descriptors.
Advantages of Protected Mode:
1. More Powerful: Offers greater flexibility and capability than real mode.
2. Full Memory Access: No 1MB limit, allowing access to the entire system memory.
3. Multitasking: Enables simultaneous execution of multiple programs.
4. Virtual Memory: Uses the hard disk to extend system memory.
5. Faster Memory Access: Supports 32-bit memory and faster I/O transfers.
Protection Fault
A protection fault occurs when a program tries to access a memory location it is not authorized
to use.
Why Protected Mode is Named as It?
Protected Mode is named for its ability to protect memory regions in a multitasking
environment. In this mode, the operating system can manage multiple programs running at the
same time, each with its own protected memory space. This prevents programs from interfering
with each other's memory, ensuring system stability and security.
Real mode vs Protected mode memory addressing:
Feature Real Mode Protected Mode
Accesses only the first 1MB of Full access to all system memory, beyond
Memory Access
memory 1MB
Addressing
Segment: Offset addressing Selector: Descriptor addressing
Method
Memory No protection between Memory protection for each program,
Protection programs preventing conflicts
Supports multitasking (multiple programs
Multitasking Not supported
running simultaneously)
Supports virtual memory (using hard disk
Virtual Memory Not supported
as additional memory)
Limited by 16-bit addressing Faster with 32-bit addressing, better
Speed
and performance performance
Math:
Descriptor Format:
The base address of the descriptor indicates the starting location of the memory segment.
Limit contains the last offset address.
The G, or granularity bit:
• G = 1: 32-bit offset address allows segment lengths of 4G bytes.
• G = 0: 16-bit offset address allows segment lengths of 64K bytes.
AV bit indicates if the segment is available (AV = 1) or not available (AV = 0).
D = 0: Instructions are 16-bit.
D = 1: Instructions are 32-bit.
Access rights byte:
It controls access to the protected mode segment.
Privilege Level:
Privilege Levels (PL) are used to control access to different levels of memory, ensuring security
and stability of the system.00 is Higher priority 11 is lower Priority.
• Requested Privilege Level (RPL): Part of selector field in the segment register.
• Descriptor Privilege Level (DPL): This is a part of Access rights byte.
• If RPL>=DPL request will be granted