Chapter 4 Microcomputer System Design
Chapter 4 Microcomputer System Design
1. Microcomputer Organization
A microcomputer is a small, relatively inexpensive computer with a microprocessor as its Central Processing Unit (CPU). It is typically used
by one person at a time (hence "personal computer"). The basic organization of a microcomputer involves several interconnected functional
units.
1. Central Processing Unit (CPU): The "brain" of the computer, responsible for executing instructions and performing arithmetic
and logical operations. In microcomputers, the CPU is typically a single integrated circuit called a microprocessor.
2. Memory Unit: Stores programs (instructions) and data. It can be categorized into:
o Primary Memory (Main Memory): Fast, volatile memory (RAM - Random Access Memory) directly accessible by
the CPU, used for currently executing programs and data.
o Secondary Memory (Auxiliary Memory): Slower, non-volatile memory (e.g., Hard Disk Drives, Solid State Drives,
USB drives) used for long-term storage of programs and data.
3. Input/Output (I/O) Unit: Facilitates communication between the computer and the outside world.
o Input Devices: Allow users to enter data and commands (e.g., keyboard, mouse, scanner, microphone).
o Output Devices: Display or present the results of processing (e.g., monitor, printer, speakers).
o I/O Interface: Hardware that mediates between the CPU/memory and the I/O devices, handling differences in data
formats, speeds, and electrical signals.
4. Buses: Collections of electrical conductors that provide communication pathways between the various components of the
computer system.
o Address Bus: Carries memory addresses from the CPU to memory or I/O devices to specify the location for data
transfer. It is unidirectional.
o Data Bus: Carries data between the CPU, memory, and I/O devices. It is bidirectional.
o Control Bus: Carries control signals from the CPU to other components (e.g., read/write signals, interrupt requests)
and status signals from devices back to the CPU. It is bidirectional.
Operation: The CPU fetches instructions from memory, decodes them, and then executes them. During execution, the CPU may read data
from memory or input devices, perform computations, and write results to memory or output devices. All these operations are coordinated
via the buses.
2. Microprocessor Organization
A microprocessor is a single-chip CPU. Its internal organization includes several key functional units that work together to fetch, decode,
and execute instructions.
Microprocessor's Internal Bus Structure: Microprocessors often have internal buses connecting their components (ALU, CU, Registers)
to allow fast data transfer within the chip.
Fetch-Decode-Execute Cycle (Instruction Cycle): The fundamental operation of a microprocessor follows a cycle:
1. Fetch: The CPU fetches the instruction from the memory location pointed to by the Program Counter (PC) and stores it in the
Instruction Register (IR). The PC is then incremented.
2. Decode: The Control Unit decodes the instruction in the IR to determine the operation and the operands required.
3. Execute: The Control Unit generates the necessary control signals to perform the operation. This might involve:
o Loading operands from registers or memory.
o Performing an arithmetic/logical operation in the ALU.
o Storing the result in a register or memory.
o Updating flags in the Status Register.
Instructions: An instruction is a binary code that specifies an operation to be performed by the CPU and the operands (data or addresses)
involved in that operation. The set of all instructions that a CPU can understand and execute is called its instruction set.
1. Opcode (Operation Code): Specifies the operation to be performed (e.g., ADD, SUB, MOV, JUMP).
2. Operand(s) / Address Field(s): Specify the data or the memory addresses of the data on which the operation is to be performed.
An instruction can have zero, one, two, or three address fields.
● Zero-Address Instruction (Stack-based): Operands are implicitly taken from/pushed onto a stack. (e.g., ADD - pops two
operands, pushes result)
● One-Address Instruction (Accumulator-based): One operand is implicitly the Accumulator. (e.g., ADD X - adds content of X to
Accumulator)
● Two-Address Instruction: Specifies two operands. (e.g., ADD R1, R2 - R1 = R1 + R2)
● Three-Address Instruction: Specifies three operands (two sources, one destination). (e.g., ADD R1, R2, R3 - R1 = R2 + R3)
Addressing Modes: Addressing modes define how the operand (data) or the effective address of the operand is specified in the instruction.
They determine how the CPU finds the data it needs to perform an operation.
Subroutines (Procedures/Functions): A subroutine is a self-contained block of code that performs a specific task and can be called
(invoked) multiple times from different parts of a main program.
● Purpose:
o Modularity: Breaks down large programs into smaller, manageable units.
o Reusability: Avoids code duplication; a common task can be written once and called wherever needed.
o Simplicity: Improves program structure and readability.
o Memory Efficiency: Reduces program size as common code is stored only once.
● Mechanism:
o CALL Instruction: When a CALL instruction is executed, the CPU first pushes the return address (the address of
the instruction immediately following the CALL instruction in the main program) onto a special memory area called the
stack. Then, the Program Counter (PC) is loaded with the starting address of the subroutine, causing execution to
jump to the subroutine.
o RETURN Instruction: At the end of the subroutine, a RET (return) instruction is encountered. This instruction pops
the return address from the top of the stack and loads it back into the PC. This causes program execution to resume
from where it left off in the main program.
o Stack: The stack is a Last-In, First-Out (LIFO) data structure used to store return addresses, parameters, and local
variables during subroutine calls.
● Nesting of Subroutines: One subroutine can call another subroutine. The stack mechanism naturally handles this by pushing
multiple return addresses.
Interrupts: An interrupt is an event that causes the CPU to temporarily suspend its current execution, save its current state, and transfer
control to a special routine called an Interrupt Service Routine (ISR) or Interrupt Handler. After the ISR completes its task, the CPU
restores its original state and resumes the interrupted program.
● Purpose:
o Event Handling: Allows the CPU to respond to asynchronous events (e.g., keyboard input, printer ready, disk
transfer complete, timer expiry) without constantly polling devices.
o Efficient I/O: Prevents the CPU from wasting time waiting for slow I/O devices.
o Error Handling: Catches unexpected events like power failure or division by zero.
o Multitasking/Operating Systems: Enables the OS to manage multiple programs concurrently by switching between
them.
● Types of Interrupts:
0. Hardware Interrupts:
▪ Generated by external hardware devices (e.g., keyboard press, mouse movement, printer paper jam, disk
I/O completion).
▪ Signal sent via dedicated interrupt lines to the CPU.
▪ Can be maskable (can be enabled/disabled by software) or non-maskable (cannot be disabled, critical
events like power failure).
1. Software Interrupts (Traps/Exceptions):
▪ Generated by software instructions (e.g., INT instruction in x86) or by internal CPU events (e.g., division
by zero, overflow, invalid opcode, page fault).
▪ Often used by operating systems for system calls (e.g., requesting I/O service).
● Interrupt Handling Process:
0. Interrupt Request: A device or internal event generates an interrupt signal.
1. Current Instruction Completion: The CPU typically completes the execution of the current instruction before
acknowledging the interrupt.
2. State Saving: The CPU saves the current state of the program (e.g., contents of the Program Counter, Flag Register,
and sometimes other critical registers) onto the stack.
3. Interrupt Acknowledgment: The CPU acknowledges the interrupt.
4. ISR Address Determination: The CPU determines the starting address of the appropriate ISR. This is often done via
an interrupt vector table, which is a table in memory containing the starting addresses of various ISRs. The interrupt
source provides an "interrupt number" or "vector" that points to the correct entry in this table.
5. ISR Execution: The CPU loads the ISR address into the PC and begins executing the ISR.
6. State Restoration: After the ISR completes its task, it executes an IRET (Interrupt Return) instruction. This
instruction pops the saved state (PC, flags, etc.) from the stack, restoring the CPU to its state before the interrupt.
7. Resumption: The CPU resumes execution of the interrupted program from where it left off.
● Priority Interrupts: When multiple interrupts occur simultaneously, a priority scheme is used to determine which interrupt is
serviced first. High-priority interrupts can interrupt lower-priority ISRs.
o Hardware Priority (Daisy Chaining, Parallel Priority): Physical connections define priority.
o Software Priority (Polling): CPU polls devices in a specific order to check for interrupts.
5. Memory Organization
Memory organization refers to how memory is structured and accessed within a computer system. It deals with different types of memory,
their characteristics, and how they are arranged to provide efficient storage and retrieval of data and instructions.
Memory Hierarchy: Computer systems use a memory hierarchy to balance speed, cost, and capacity. Faster, more expensive memory is
placed closer to the CPU, while slower, cheaper memory is used for larger storage.
CPU
|
| (Fastest, Smallest, Most Expensive)
|
+-----+
| Cache | (L1, L2, L3)
+-----+
|
+------------+
| Main Memory| (RAM - Primary Storage)
+------------+
|
+--------------+
| Auxiliary Mem| (HDD, SSD - Secondary Storage)
+--------------+
|
+-------------+
| Tertiary Mem| (Tapes, Optical - Offline/Archival)
+-------------+
Types of Memory:
1. CPU Registers:
o Characteristics: Smallest, fastest, most expensive storage, directly within the CPU.
o Purpose: Hold data and instructions actively being processed. Volatile.
2. Cache Memory:
o Characteristics: Small, very fast SRAM (Static RAM) memory, located between the CPU and main memory. Levels
(L1, L2, L3) exist, with L1 being fastest and closest to the CPU.
o Purpose: Stores copies of frequently accessed data and instructions from main memory to reduce average memory
access time. Volatile.
3. Main Memory (Primary Memory):
o Characteristics: RAM (Random Access Memory) - the primary working memory. Larger than cache, slower than
cache, faster than auxiliary memory. Volatile.
o Types of RAM:
▪SRAM (Static RAM): Faster, more expensive, uses latches, does not need refreshing. Used for cache.
▪DRAM (Dynamic RAM): Slower, cheaper, uses capacitors, needs periodic refreshing to retain data. Used
for main memory.
o Purpose: Stores programs and data that the CPU is actively using.
4. Read-Only Memory (ROM):
o Characteristics: Non-volatile memory, data is permanent or semi-permanent.
o Types:
▪ ROM: Programmed at manufacturing time.
▪ PROM (Programmable ROM): Can be programmed once by the user.
▪ EPROM (Erasable PROM): Can be erased by UV light and reprogrammed.
▪ EEPROM (Electrically Erasable PROM): Can be erased electrically and reprogrammed.
▪ Flash Memory: A type of EEPROM, widely used in SSDs, USB drives, etc., for its non-volatility and fast
read/write.
o Purpose: Stores firmware, BIOS (Basic Input/Output System), bootstrap loader.
5. Auxiliary Memory (Secondary Memory):
o Characteristics: Large capacity, non-volatile, much slower and cheaper per bit than main memory.
o Purpose: Long-term storage of programs, operating system, and data.
o Examples: Hard Disk Drives (HDDs), Solid State Drives (SSDs), Optical Discs (CD/DVD/Blu-ray), Magnetic Tapes,
USB Flash Drives.
Memory Addressing:
Memory Mapping:
6. Input-Output Interface
An I/O interface is a hardware component that acts as a bridge between the CPU/memory and peripheral devices (input/output devices). It
resolves the inherent differences between the CPU and peripherals.
1. Data Transfer Rates: CPUs operate at very high speeds, while peripherals are significantly slower. The interface buffers data to
accommodate this speed mismatch.
2. Data Formats: Peripherals may use different data formats (e.g., serial data for keyboard, parallel data for printer) compared to
the CPU's internal format. The interface handles conversion.
3. Electrical Characteristics: Different voltage levels and signal types exist. The interface provides electrical compatibility.
4. Operating Modes: Each peripheral has its own specific mode of operation and control requirements. The interface translates
generic CPU commands into device-specific commands.
5. Synchronization: CPU and peripherals are asynchronous. The interface provides synchronization mechanisms (e.g., status flags,
interrupts).
1. Buffer Registers (Data Registers): Temporary storage for data being transferred between the CPU and the I/O device.
2. Status Register: Contains bits that indicate the current status of the I/O device (e.g., ready, busy, error). The CPU can read this
register.
3. Control Register: Contains bits that the CPU can write to, to send commands or configure the I/O device (e.g., enable/disable
interrupts, set data transfer mode).
4. Address Decoding Logic: Decodes the I/O address placed on the address bus by the CPU to select the correct peripheral device
and its specific registers (data, status, control).
5. Control Logic: Interprets the control signals from the CPU and generates appropriate control signals for the peripheral. It also
generates status signals back to the CPU.
6. Interrupt Logic: Manages interrupt requests from the peripheral to the CPU.
I/O Port Addressing: There are two main ways the CPU can access I/O device registers:
1. Memory-Mapped I/O:
o Description: I/O device registers (data, status, control) are assigned unique addresses within the same address space
as main memory.
o Access: The CPU uses regular memory read/write instructions (e.g., MOV in x86) to access I/O registers.
o Advantages:
▪ No special I/O instructions are needed.
▪ All memory-addressing modes can be used for I/O.
o Disadvantages:
▪ A portion of the memory address space is used for I/O, reducing available memory.
▪ Memory cache might interfere with I/O operations if not handled carefully.
2. Isolated I/O (Port-Mapped I/O):
o Description: I/O device registers have a separate address space distinct from memory.
o Access: The CPU uses special I/O instructions (e.g., IN, OUT in x86) to access I/O ports.
o Advantages:
▪ Separate address spaces mean no memory address space is consumed by I/O.
▪ Clear distinction between memory and I/O operations.
o Disadvantages:
▪ Requires dedicated I/O instructions.
▪ Fewer addressing modes might be available for I/O operations compared to memory.
7. Programmed Input-Output (PIO)
Programmed I/O is a method of data transfer where the CPU is directly involved in every step of the I/O operation. The CPU executes a
program that continuously monitors the status of the I/O device and performs the actual data transfer.
Working Principle:
1. The CPU issues an I/O command to the peripheral device via the I/O interface's control register.
2. The CPU then enters a busy-wait loop (polling), repeatedly reading the status register of the I/O device to check if the device is
ready for data transfer or if the operation is complete.
3. Once the status indicates the device is ready, the CPU reads data from the I/O data register (for input) or writes data to it (for
output).
4. This process is repeated for every byte or word of data transferred.
Steps for a Programmed I/O Input Operation (e.g., reading from keyboard):
1. The CPU sends a command to the keyboard interface to prepare for input.
2. The CPU repeatedly checks the status register of the keyboard interface.
3. If the "data ready" bit in the status register is not set, the CPU continues to loop (busy-wait).
4. Once a key is pressed, the keyboard interface sets the "data ready" bit.
5. The CPU detects the "data ready" bit, reads the character from the keyboard interface's data register into a CPU register.
6. The CPU then transfers this data from the CPU register to memory.
7. The keyboard interface clears the "data ready" bit.
● CPU Overhead: The CPU spends a significant amount of time polling the I/O device, idly waiting for the device to become
ready. This is inefficient, especially for slow devices.
● Low Throughput: The overall system performance degrades significantly as the CPU is tied up.
● No Concurrency: The CPU cannot perform other tasks while waiting for I/O operations to complete. This is unacceptable in
multi-tasking environments.
Use Cases: Programmed I/O is typically used in very simple embedded systems where CPU time is not critical, or for initial boot-up
processes where only basic I/O is required before more advanced mechanisms are set up.
An Input-Output Processor (IOP), also known as an I/O Channel or Channel Processor, is a specialized processor designed to handle I/O
operations independently of the main CPU. It allows the main CPU to execute application programs concurrently with I/O operations.
Purpose: To offload I/O management tasks from the main CPU, thereby improving overall system performance and efficiency.
Working Principle:
1. The main CPU initiates an I/O operation by sending a high-level command (e.g., "read file X from disk into memory location
Y") to the IOP.
2. The CPU then continues with its own processing tasks.
3. The IOP takes over the I/O operation. It has its own instruction set, registers, and control logic specifically optimized for I/O.
4. The IOP fetches its own I/O instructions (called commands or channel programs) from main memory. These commands
specify the device, operation, memory buffer address, and transfer size.
5. The IOP executes these commands, managing the data transfer between the peripheral device and main memory. This often
involves using Direct Memory Access (DMA).
6. Upon completion of the I/O operation (or in case of an error), the IOP generates an interrupt to the main CPU to signal that the
task is finished.
7. The CPU can then retrieve the status of the I/O operation from the IOP's status registers.
Features of an IOP:
● CPU Relief: Frees the main CPU from the burden of detailed I/O management, allowing it to focus on computation.
● Increased Concurrency: CPU and I/O operations can happen in parallel, significantly improving system throughput.
● Modular Design: Separates I/O logic from main CPU logic.
● Scalability: Allows adding more I/O devices without significantly impacting CPU performance.
Example: In large mainframe computers, I/O channels are sophisticated IOPs that manage complex I/O subsystems. In modern PCs,
specialized controllers for hard drives (SATA controllers), network cards, and graphics cards often incorporate IOP-like functionalities and
use DMA.
Input/Output (I/O) devices are the hardware components that allow a computer to interact with the outside world. They vary widely in their
characteristics, which directly impact how they are interfaced with the computer.
Understanding these characteristics helps in designing appropriate I/O interfaces and choosing the most efficient data transfer methods for
each device.
10. Direct Memory Access (DMA)
Direct Memory Access (DMA) is a hardware-controlled data transfer technique that allows an I/O device to transfer data directly to and
from main memory without the continuous involvement of the CPU. This significantly improves data transfer speed and system
efficiency, especially for high-speed I/O devices.
DMA Controller (DMAC): The core component of DMA is a special-purpose hardware unit called the DMA Controller (DMAC). The
DMAC manages the entire data transfer process once initiated by the CPU.
1. CPU Initialization:
o The CPU programs the DMAC by writing to its internal registers:
▪ Source Address Register: Stores the starting address of the data block in memory (for output) or the
starting address in the I/O device (for input, if device-side addressing is possible).
▪ Destination Address Register: Stores the starting address in the I/O device (for output) or the starting
address in memory (for input).
▪ Word Count Register: Stores the number of bytes/words to be transferred.
▪ Control Register: Specifies the transfer mode (e.g., read/write, burst mode, cycle stealing),
source/destination increment/decrement behavior, and other settings.
o After programming, the CPU sends a "start" command to the DMAC. The CPU then resumes its other tasks.
2. DMA Request (DRQ):
o The I/O device, when ready to transfer data, sends a DMA Request (DRQ) signal to the DMAC.
3. Bus Request (BR) and Bus Grant (BG):
o The DMAC, upon receiving DRQ, sends a Bus Request (BR) signal to the CPU (or bus arbiter).
o The CPU, upon receiving BR, finishes its current bus cycle and then relinquishes control of the system buses
(address, data, control) by asserting a Bus Grant (BG) signal back to the DMAC. The CPU essentially enters a
"halted" or "idle" state regarding bus access.
4. Data Transfer:
o Once the DMAC receives BG, it takes control of the buses.
o It uses its own address and data registers to directly transfer data between the I/O device and memory, one word/byte
at a time, for the specified count. The CPU is bypassed for this data transfer.
o The DMAC automatically increments/decrements its internal address registers and decrements the word count
register.
5. DMA Completion and Interrupt:
o When the word count reaches zero (all data transferred), the DMAC releases control of the buses by deactivating BR.
o It then sends an Interrupt Request (IRQ) signal to the CPU to indicate the completion of the DMA transfer.
o The CPU can then process the data, check for errors, and potentially initiate the next DMA transfer.
Advantages of DMA:
● High Speed Data Transfer: Ideal for transferring large blocks of data rapidly (e.g., disk I/O, network communication).
● Reduced CPU Overhead: Frees the CPU to perform other computational tasks, leading to better overall system performance
and throughput.
● Increased Concurrency: Allows parallel execution of CPU tasks and I/O operations.
Disadvantages of DMA:
● Increased Hardware Complexity: Requires a dedicated DMAC, adding to hardware cost and complexity.
● Bus Contention: DMAC competes with the CPU for bus access, which needs careful arbitration.
● Cache Coherency Issues: If the CPU caches data that is modified by DMA, cache coherency mechanisms are needed to ensure
the CPU always has the latest data.
DMA is a critical feature in modern computer systems, enabling high-performance data transfers for almost all high-speed peripherals.