Comprehensive Study Notes on 8086 Microprocessor Architecture, Programming, Interrupts, and Serial Communication

Microprocessor Fundamentals: Comparison Between 8085 and 8086

  • Intel introduced the 8086 microprocessor in 1976 as an advanced, 16-bit enhancement of the earlier 8-bit 8085 microprocessor.

  • The 8086 is fabricated using N-channel, High-speed Metal Oxide Semiconductor (HMOS) technology and housed in a 40-pin Dual Inline Package (DIP).

  • Structural and operational distinctions between the 8085 and 8086 processors:

    • Data Bus Width: The 8085 has an 8-bit data bus; the 8086 features a 16-bit data bus, allowing it to read or write 16 bits (one word) in a single bus cycle.

    • Address Bus Width and Memory Capacity: The 8085 provides a 16-bit address line addressing up to 216=64 KB2^{16} = 64\,\text{KB} of memory. The 8086 provides a 20-bit address line addressing up to 220=1 MB2^{20} = 1\,\text{MB} (1,048,576 bytes1{,}048{,}576\,\text{bytes}) of physical memory space.

    • Clock Frequencies: The 8085 typically operates at a clock speed of 3 MHz3\,\text{MHz}. The 8086 offers versions operating at clock frequencies of 5 MHz5\,\text{MHz} (standard 8086), 8 MHz8\,\text{MHz} (8086-2), and 10 MHz10\,\text{MHz} (8086-1).

    • Flag Register: The 8085 contains 5 active flags. The 8086 features 9 active flags (6 conditional/status flags and 3 control flags) embedded in a 16-bit flag register.

    • Memory Segmentation: The 8085 has a single flat memory space without hardware segmentation. The 8086 implements memory segmentation, dividing physical memory into logical segments of up to 64 KB64\,\text{KB} each.

    • Pipelining and Instruction Queue: The 8085 lacks instruction prefetching and pipelining (fetch and execute phases are strictly sequential). The 8086 incorporates a 6-byte instruction pre-fetch queue that allows overlapping instruction fetching with execution.

    • Processor Architecture Model: The 8085 is an accumulator-based microprocessor (the accumulator register AA is heavily tied to ALU operations). The 8086 is a general-purpose register-based processor.

    • Operating Modes: The 8085 operates in a single configuration mode. The 8086 operates in two distinct hardware modes: Minimum Mode (single-processor systems) and Maximum Mode (multiprocessor or coprocessor configurations).

    • Multiprocessing Support: In 8085 systems, only a single processor is used. In 8086 systems, multiple processors or external numeric data coprocessors (such as the 8087) can be employed.

    • Integration Density: The 8085 contains approximately 6,5006{,}500 transistors. The 8086 integrates approximately 29,00029{,}000 transistors.

    • System Cost: The 8085 involves lower implementation and chip costs, whereas the 8086 has a higher system design and component cost.

Intel 8086 Architecture and Register Organization

Block Diagram of 8086 Microprocessor
  • The internal architecture of the 8086 is partitioned into two independent processing units working concurrently to implement pipelining: the Bus Interface Unit (BIU) and the Execution Unit (EU).

  • Bus Interface Unit (BIU):

    • Interfaces directly with the system buses to execute all memory read/write cycles, instruction fetching, and I/O port read/write operations.

    • Contains the dedicated 20-bit address calculation adder circuit, calculating physical memory addresses using the relation:     Physical Address=(Segment Address×10H)+Offset\text{Physical Address} = (\text{Segment Address} \times 10\text{H}) + \text{Offset}

    • Holds the 6-Byte Instruction Pre-fetch Queue, constructed using First-In, First-Out (FIFO) registers. While the Execution Unit executes an instruction, the BIU continuously prefetches up to 6 bytes of upcoming instruction code from memory, eliminating fetch-cycle latency.

    • Houses the four 16-bit Segment Registers:

    • Code Segment (CS): Points to the base of the code segment containing executable instructions.

    • Data Segment (DS): Points to the base of the data segment holding program variables and operands.

    • Stack Segment (SS): Points to the base of the stack segment dedicated to stack data and return addresses.

    • Extra Segment (ES): Serves as an additional data segment, commonly used for destination data in string operations.

    • Holds the 16-bit Instruction Pointer (IP) register, which holds the 16-bit offset address of the next sequential byte to be fetched from the Code Segment (CS:IP\text{CS}:\text{IP}). The IP is not directly accessible or alterable by programmer instructions; it updates automatically or via control transfer instructions.

  • Execution Unit (EU):

    • Responsible for decoding instructions, fetching operands from general-purpose registers or the BIU internal data bus, executing arithmetic and logic operations, and updating condition flags.

    • Contains the Arithmetic Logic Unit (ALU), which handles 8-bit and 16-bit arithmetic (addition, subtraction, multiplication, division) and logical operations.

    • Houses the Control Unit, which generates internal timing and control signals based on decoded opcodes.

    • Contains four 16-bit General Purpose Registers, which can also be addressed as eight individual 8-bit registers (High and Low bytes):

    • AX (Accumulator Register): Divided into AH\text{AH} and AL\text{AL}. Preferred register for arithmetic, logical, and data transfer operations as it yields the most compact machine code; mandatory for hardware multiplication, division, and direct I/O port instructions.

    • BX (Base Register): Divided into BH\text{BH} and BL\text{BL}. Commonly used for base addressing and can store memory offset addresses.

    • CX (Count Register): Divided into CH\text{CH} and CL\text{CL}. Serves as an automatic loop counter in loop instructions (LOOP, JCXZ) and as a shift/rotate bit-counter via CL\text{CL}.

    • DX (Data Register): Divided into DH\text{DH} and DL\text{DL}. Holds high-order bits during 32-bit multiplication/division results and acts as an indirect I/O port address pointer ([DX]).

    • Houses four 16-bit Pointer and Index Registers (accessible only as full 16-bit words, not split into high/low bytes):

    • Stack Pointer (SP): Holds the offset address to the current top of the stack within the Stack Segment (SS:SP\text{SS}:\text{SP}).

    • Base Pointer (BP): Primarily used to access parameters and local variables on the stack frame; defaults to the Stack Segment (SS:BP\text{SS}:\text{BP}).

    • Source Index (SI): Holds offset addresses when accessing data in the Data Segment; serves as the source offset in string operations (DS:SI\text{DS}:\text{SI}).

    • Destination Index (DI): Holds memory offset addresses; acts as the destination string offset in string operations (ES:DI\text{ES}:\text{DI}).

  • Flag Register (Status and Control Flags):

Flag Register Configuration
  • Consists of a 16-bit register where 9 bits function as active status or control indicators, while the remaining 7 bits are undefined/reserved (marked as XX):

    • High Byte (FlagsH\text{Flags}_H): X, X, X, X, OF, DF, IF, TF

    • Low Byte (FlagsL\text{Flags}_L): SF, ZF, X, AF, X, PF, X, CF

  • Six Conditional / Status Flags: Set (11) or cleared (00) automatically based on the result of an arithmetic or logical operation:

    • Carry Flag (CF, bit 0): Sets to 11 if an arithmetic operation generates a carry out of the most significant bit (for addition) or a borrow (for subtraction); otherwise cleared to 00.

    • Parity Flag (PF, bit 2): Sets to 11 if the low-order 8 bits of the result contain an even number of 11s (even parity); clears to 00 if odd parity.

    • Auxiliary Carry Flag (AF / AC, bit 4): Sets to 11 if a carry or borrow occurs from bit D3D_3 to bit D4D_4 (between the low and high nibbles) during binary-coded decimal (BCD) arithmetic. This is the only flag register bit that cannot be directly tested by branch instructions.

    • Zero Flag (ZF, bit 6): Sets to 11 if the mathematical or logical result of an operation is exactly zero (00H00\text{H} or 0000H0000\text{H}); cleared to 00 if non-zero.

    • Sign Flag (SF, bit 7): Copies the most significant bit (MSB) of the result (D7D_7 for 8-bit, D15D_{15} for 16-bit). 11 indicates a negative result, and 00 indicates a positive result.

    • Overflow Flag (OF, bit 11): Sets to 11 when the signed arithmetic result is too large (positive or negative) to fit in the destination register; signals an arithmetic overflow in two's complement operations.

  • Three Control Flags: Enable or disable specific processor operations:

    • Trap Flag (TF, bit 8): When set to 11, puts the processor into single-step execution mode for on-chip debugging. The CPU generates an internal Type 1 interrupt after executing each individual instruction.

    • Interrupt Enable Flag (IF, bit 9): When set to 11, the microprocessor recognizes external maskable hardware interrupt requests arriving on the INTR\text{INTR} pin. When cleared to 00, maskable interrupts are ignored.

    • Direction Flag (DF, bit 10): Used exclusively by string instructions. If DF=0\text{DF} = 0 (cleared via CLD), auto-indexing increments SI\text{SI} and DI\text{DI} (string processing moves from low memory to high memory). If DF=1\text{DF} = 1 (set via STD), auto-indexing decrements SI\text{SI} and DI\text{DI} (string processing moves from high memory to low memory).

Pin Configuration and Signals of the 8086 Microprocessor

8086 Pinout Configuration
  • The 8086 is a 40-pin Dual Inline Package integrated circuit powered by a single +5 V DC+5\,\text{V DC} supply connected to VCCV_{CC} (pin 40), with reference ground connections on pins 1 (GND\text{GND}) and 20 (GND\text{GND}).

  • Pin functions are divided into common signals, Minimum Mode signals, and Maximum Mode signals (determined by pin 33, MN/MX‾\text{MN}/\overline{\text{MX}}).

  • Common Signals (Pins 1–23 and 32–40):

    • AD0−AD15AD_0 - AD_{15} (Pins 16–9, 8–2, 39): Bidirectional, time-multiplexed Address/Data bus. During bus state T1T_1, they carry low-order memory addresses (A0−A15A_0 - A_{15}) or I/O addresses. During states T2,T3,Tw,T_2, T_3, T_w, and T4T_4, they carry 16-bit data (D0−D15D_0 - D_{15}).

    • A16/S3−A19/S6A_{16}/S_3 - A_{19}/S_6 (Pins 38–35): Time-multiplexed high-order address lines and bus status lines. Address bits A16−A19A_{16}-A_{19} are output during T1T_1. During T2,T3,Tw,T_2, T_3, T_w, and T4T_4, they output status bits S3,S4,S5,S6S_3, S_4, S_5, S_6:

    • Bits S4,S3S_4, S_3 encode the segment register used for the current bus cycle (00=ES00 = \text{ES}, 01=SS01 = \text{SS}, 10=CS or None10 = \text{CS or None}, 11=DS11 = \text{DS}).

    • Bit S5S_5 indicates the state of the Interrupt Enable Flag (IF).

    • Bit S6S_6 is always held at logic 00.

    • BHE‾/S7\overline{\text{BHE}}/S_7 (Pin 34): Bus High Enable / Status line. Asserted active low during T1T_1 to enable data onto the most significant half of the data bus (D8−D15D_8 - D_{15}). Used when transferring a byte to/from an odd memory address or a full 16-bit word. Multiplexed with status signal S7S_7 during later clock states.

    • RD‾\overline{\text{RD}} (Pin 32): Read strobe, active low output. Indicates the processor is reading memory or I/O data.

    • READY\text{READY} (Pin 22): Active high input signal from addressed memory or I/O devices indicating data transfer readiness; if low, the processor inserts wait states (TwT_w).

    • RESET\text{RESET} (Pin 21): System reset, active high input. Must remain high for at least 4 clock cycles to clear internal registers, setting CS=FFFFH\text{CS} = \text{FFFFH} and IP=0000H\text{IP} = 0000\text{H}.

    • CLK\text{CLK} (Pin 19): Clock input providing internal timing, operating at 5 MHz5\,\text{MHz}, 8 MHz8\,\text{MHz}, or 10 MHz10\,\text{MHz}.

    • INTR\text{INTR} (Pin 18): Interrupt Request, level-triggered active high input sampled during the final clock state of each instruction.

    • NMI\text{NMI} (Pin 17): Non-Maskable Interrupt, positive edge-triggered input (0→10 \rightarrow 1). Must remain high until recognized, and must be held at logic 00 for at least 2 clock cycles before the transition.

    • TEST‾\overline{\text{TEST}} (Pin 23): Active low input evaluated by the WAIT instruction. If low, execution proceeds; if high, the CPU idles.

    • MN/MX‾\text{MN}/\overline{\text{MX}} (Pin 33): Mode selection pin. Connected to +5 V+5\,\text{V} for Minimum Mode; tied to Ground for Maximum Mode.

  • Minimum Mode Signals (MN/MX‾=VCC\text{MN}/\overline{\text{MX}} = V_{CC}, Pins 24–31):

    • HOLD\text{HOLD} (Pin 31): Bus request input from DMA controllers.

    • HLDA\text{HLDA} (Pin 30): Hold Acknowledge output signaling the CPU has placed the buses into high-impedance state.

    • WR‾\overline{\text{WR}} (Pin 29): Write strobe, active low output.

    • M/IO‾M/\overline{\text{IO}} (Pin 28): Output distinguishing memory access (high) from I/O port access (low).

    • DT/R‾\text{DT}/\overline{\text{R}} (Pin 27): Data Transmit/Receive output controlling the direction of bidirectional bus transceivers (1=transmit1 = \text{transmit}, 0=receive0 = \text{receive}).

    • DEN‾\overline{\text{DEN}} (Pin 26): Data Enable, active low output enabling external data bus transceivers.

    • ALE\text{ALE} (Pin 25): Address Latch Enable, active high pulse used to latch the address from multiplexed lines into external latches (e.g., 8282/74LS373) during T1T_1.

    • INTA‾\overline{\text{INTA}} (Pin 24): Interrupt Acknowledge, active low output pulse generated in response to an INTR\text{INTR} input.

  • Maximum Mode Signals (MN/MX‾=GND\text{MN}/\overline{\text{MX}} = \text{GND}, Pins 24–31):

    • RQ‾/GT0‾\overline{\text{RQ}}/\overline{\text{GT}_0} and RQ‾/GT1‾\overline{\text{RQ}}/\overline{\text{GT}_1} (Pins 31, 30): Bidirectional lines used by other bus masters to request and obtain bus control.

    • LOCK‾\overline{\text{LOCK}} (Pin 29): Output asserting that other system bus masters cannot seize bus ownership during the locked instruction.

    • S2‾,S1‾,S0‾\overline{S_2}, \overline{S_1}, \overline{S_0} (Pins 28, 27, 26): Status outputs decoded by the external 8288 Bus Controller to generate system read/write bus commands.

    • QS0,QS1QS_0, QS_1 (Pins 25, 24): Queue Status outputs reflecting internal instruction queue operations (00=no operation00 = \text{no operation}, 01=first byte of opcode01 = \text{first byte of opcode}, 10=empty queue10 = \text{empty queue}, 11=subsequent byte of opcode11 = \text{subsequent byte of opcode}).

Memory Segmentation, Stack Organization, and Physical Address Calculation

  • Memory Segmentation Principles:

    • The 1 MB1\,\text{MB} physical address space (00000H00000\text{H} to FFFFFH\text{FFFFFH}) is organized into logical segments of up to 64 KB64\,\text{KB} (65,536 bytes65{,}536\,\text{bytes}).

    • Segment base addresses always begin on 16-byte boundaries (known as paragraph boundaries, where the lowest hexadecimal digit is 0H0\text{H}).

    • Standard segment register pairing with offset registers:

    • Code Segment (CS\text{CS}): paired with Instruction Pointer (IP\text{IP}) to fetch instruction opcodes.

    • Data Segment (DS\text{DS}): paired with BXBX, DIDI, or SISI for regular data operands.

    • Stack Segment (SS\text{SS}): paired with Stack Pointer (SPSP) or Base Pointer (BPBP) for stack operations.

    • Extra Segment (ES\text{ES}): paired with DIDI (and BXBX or SISI) for string destinations and general data.

  • Step-by-Step Physical Address Calculation Algorithm:

    • Step 1 (Compute Effective Address): Calculate the effective offset address (EA\text{EA}) using the specified registers and displacements:     EA=[Base Register]+[Index Register]+Displacement\text{EA} = [\text{Base Register}] + [\text{Index Register}] + \text{Displacement}

    • Step 2 (Identify Default Segment): Apply default hardware rules:

    • If the base/offset expression contains BPBP, the default segment is the Stack Segment (SS).

    • If the expression uses BXBX, SISI, or DIDI (without BPBP), the default segment is the Data Segment (DS).

    • Step 3 (Calculate Segment Base): Shift the 16-bit segment register left by 4 bits (multiply by 10H10\text{H} or 161016_{10}):     Segment Base=Segment Register×10H\text{Segment Base} = \text{Segment Register} \times 10\text{H}

    • Step 4 (Sum Base and Offset): Add the Effective Address to the Segment Base to yield the 20-bit Physical Address (PA\text{PA}):     PA=(Segment×10H)+EA\text{PA} = (\text{Segment} \times 10\text{H}) + \text{EA}

  • Worked Numerical Address Calculation Examples:

    • Direct Addressing: Given DS=2000H\text{DS} = 2000\text{H}, Instruction MOV AX, [2500H].     Offset=2500H\text{Offset} = 2500\text{H}     Base=2000H×10H=20000H\text{Base} = 2000\text{H} \times 10\text{H} = 20000\text{H}     PA=20000H+2500H=22500H\text{PA} = 20000\text{H} + 2500\text{H} = 22500\text{H}

    • Based Addressing: Given SS=4000H,BP=1200H\text{SS} = 4000\text{H}, BP = 1200\text{H}, Instruction MOV AX, [BP].     Base=4000H×10H=40000H\text{Base} = 4000\text{H} \times 10\text{H} = 40000\text{H}     PA=40000H+1200H=41200H\text{PA} = 40000\text{H} + 1200\text{H} = 41200\text{H}

    • Based-Indexed Addressing: Given DS=2000H,BX=1000H,SI=0500H\text{DS} = 2000\text{H}, BX = 1000\text{H}, SI = 0500\text{H}, Instruction MOV AX, [BX + SI].     EA=1000H+0500H=1500H\text{EA} = 1000\text{H} + 0500\text{H} = 1500\text{H}     Base=2000H×10H=20000H\text{Base} = 2000\text{H} \times 10\text{H} = 20000\text{H}     PA=20000H+1500H=21500H\text{PA} = 20000\text{H} + 1500\text{H} = 21500\text{H}

    • Based-Indexed with Displacement: Given DS=2000H,BX=1000H,SI=0500H\text{DS} = 2000\text{H}, BX = 1000\text{H}, SI = 0500\text{H}, Instruction MOV AX, [BX + SI + 20H].     EA=1000H+0500H+20H=1520H\text{EA} = 1000\text{H} + 0500\text{H} + 20\text{H} = 1520\text{H}     PA=20000H+1520H=21520H\text{PA} = 20000\text{H} + 1520\text{H} = 21520\text{H}

    • BP with Index and Displacement: Given SS=4000H,BP=1000H,DI=0200H\text{SS} = 4000\text{H}, BP = 1000\text{H}, DI = 0200\text{H}, Instruction MOV AX, [BP + DI + 50H].     EA=1000H+0200H+50H=1250H\text{EA} = 1000\text{H} + 0200\text{H} + 50\text{H} = 1250\text{H}     Base=4000H×10H=40000H\text{Base} = 4000\text{H} \times 10\text{H} = 40000\text{H}     PA=40000H+1250H=41250H\text{PA} = 40000\text{H} + 1250\text{H} = 41250\text{H}

  • Stack Memory Mechanics:

The 8086 Stack Structure
  • The stack is a LIFO (Last-In, First-Out) memory structure growing downward from high memory toward low memory addresses.

  • The bottom of the stack resides at offset FFFEh, and the upper limit (end of stack) is at 0000h.

  • Current stack operations are referenced by the physical pointer SS:SP\text{SS}:\text{SP}.

  • PUSH Operation (16-bit word):

    • The stack pointer decrements by 2: (SP)←(SP)−2(SP) \leftarrow (SP) - 2

    • Memory address calculated: MAS=(SS)×1610+SP\text{MA}_S = (SS) \times 16_{10} + SP

    • Higher byte stored at MAS+1\text{MA}_S + 1 and lower byte at MAS\text{MA}_S

  • POP Operation (16-bit word):

    • Data retrieved from memory: Word←(MAS;MAS+1)\text{Word} \leftarrow (\text{MA}_S ; \text{MA}_S + 1)

    • The stack pointer increments by 2: (SP)←(SP)+2(SP) \leftarrow (SP) + 2

Instruction Format, Instruction Cycle, and Machine Architectures

  • Instruction Cycle State Model:

Instruction Cycle State Diagram
  • The execution cycle of a microprocessor progresses through well-defined operational states:

    • Instruction Address Calculation: Determines the next memory location (CS:IP\text{CS}:\text{IP}).

    • Instruction Fetch: Transfers the opcode from memory into the instruction queue/register.

    • Instruction Operation Decoding: Decodes the bit patterns to configure internal paths.

    • Operand Address Calculation: Resolves effective addresses for source operands involving registers or memory.

    • Operand Fetch: Retrieves operands from registers or system memory; repeats for multiple operands.

    • Data Operation: The ALU executes the requested binary arithmetic or logic operation.

    • Operand Store Address Calculation: Determines the target destination location.

    • Operand Store: Writes the result back to registers or memory; handles multiple results if generated.

    • Cycle Completion: Loops back to calculate the next instruction address, or returns for vector/string data.

    • Instruction Representation and Encoding:

  • A simple instruction format consists of 16 bits: 4 bits allocated for the Opcode, 6 bits for the first Operand Reference, and 6 bits for the second Operand Reference.

  • Operands can fall into categories: Addresses, Numbers, Characters, or Logical Data.

    • Number of Address Fields and Program Comparative Analysis:

  • Evaluation of the mathematical expression:     Y=A−BC+(D×E)Y = \frac{A - B}{C + (D \times E)}

  • 3-Address Instructions: Retains source operands while writing directly to destination; requires long words:

    • SUB Y, A, B (computes Y←A−BY \leftarrow A - B)

    • MPY T, D, E (computes T←D×ET \leftarrow D \times E)

    • ADD T, T, C (computes T←T+CT \leftarrow T + C)

    • DIV Y, Y, T (computes Y←Y÷TY \leftarrow Y \div T)

  • 2-Address Instructions: One operand field doubles as both source and destination (a=a+ba = a + b); requires temporary registers:

    • MOVE Y, A (sets Y←AY \leftarrow A)

    • SUB Y, B (sets Y←Y−BY \leftarrow Y - B)

    • MOVE T, D (sets T←DT \leftarrow D)

    • MPY T, E (sets T←T×ET \leftarrow T \times E)

    • ADD T, C (sets T←T+CT \leftarrow T + C)

    • DIV Y, T (sets Y←Y÷TY \leftarrow Y \div T)

  • 1-Address Instructions: Utilizes an implicit accumulator (ACAC) for all operations:

    • LOAD D (AC←DAC \leftarrow D)

    • MPY E (AC←AC×EAC \leftarrow AC \times E)

    • ADD C (AC←AC+CAC \leftarrow AC + C)

    • STOR Y (Y←ACY \leftarrow AC)

    • LOAD A (AC←AAC \leftarrow A)

    • SUB B (AC←AC−BAC \leftarrow AC - B)

    • DIV Y (AC←AC÷YAC \leftarrow AC \div Y)

    • STOR Y (Y←ACY \leftarrow AC)

  • 0-Address (Stack-based) Instructions: All addresses are implicit; operates on operands pushed onto the top of the stack (PUSH, POP, ADD).

Comprehensive 8086 Addressing Modes

  • An addressing mode defines how the processor locates operands. 8086 instructions fall into Sequential Control Flow Modes and Control Transfer Modes.

  • Sequential Control Flow Addressing Modes:

    • Register Addressing Mode: Operands reside exclusively within registers. Both registers must match in bit width (8-bit to 8-bit, or 16-bit to 16-bit). Segment-to-segment register movement is invalid.

    • Examples: MOV AX, BX, MOV CX, AX, ADD BX, AX

    • Immediate Addressing Mode: The source operand is constant data embedded directly in the instruction.

    • Examples: MOV AL, 22H, MOV BX, 3456H, MOV CX, 4929H, ADD AX, 2387H

    • Direct Addressing Mode: The instruction contains the 16-bit effective offset address inside brackets, defaulting to DSDS.

    • Examples: MOV AL, [1234H], MOV BX, [5000H], MOV AX, [1592H]

    • Register Indirect Addressing Mode: The offset address is stored in a pointer or index register (BX,BP,SI,DIBX, BP, SI, DI). Default segment is DSDS for BX,SI,DIBX, SI, DI, and SSSS for BPBP.

    • Examples: MOV AX, [BX], ADD CX, [BX]

    • Based Addressing Mode: The operand's offset is formed by adding an 8-bit or 16-bit displacement to a base register (BXBX or BPBP).

    • Examples: MOV DX, [BX+04], ADD CL, [BX+08], MOV AX, [BP]

    • Indexed Addressing Mode: The offset is the sum of an index register (SISI or DIDI) and an 8-bit or 16-bit displacement.

    • Examples: MOV BX, [SI+16], ADD AL, [DI+16]

    • Based-Indexed Addressing Mode: Combines one base register (BXBX or BPBP) and one index register (SISI or DIDI) to form the effective address.

    • Examples: ADD CX, [BX+SI], MOV AX, [BP+DI]

    • Based-Indexed with Displacement Mode: Combines a base register, an index register, and an immediate 8-bit or 16-bit displacement.

    • Examples: MOV AX, [BX+DI+08], ADD CX, [BX+SI+16], MOV AX, [BP+DI+50H]

    • Implied Addressing Mode: Operands are implicit to the opcode itself.

    • Examples: CLC (clears carry flag), MUL BL

    • Relative Addressing Mode: The target address is specified relative to the instruction pointer.

    • Example: JMP 200H

  • Control Transfer Addressing Modes:

    • Intrasegment Direct Addressing: The branch target lies within the current code segment (CSCS unchanged). The jump offset is specified as an immediate 8-bit or 16-bit displacement added to IPIP.

    • Example: JMP [02] (Target IP=[IP]+02H\text{Target } IP = [IP] + 02\text{H})

    • Intrasegment Indirect Addressing: The branch target address within the current code segment is fetched from a 16-bit register or memory location.

    • Example: JMP BX (the contents of register BXBX overwrite IPIP; CSCS remains identical)

    • Intersegment Direct Addressing: Branches from the current segment to a distinct segment. The instruction explicitly supplies both new 16-bit CSCS and IPIP values.

    • Example: JMP 2000H:3000H (CS←2000HCS \leftarrow 2000\text{H}, IP←3000HIP \leftarrow 3000\text{H})

    • Intersegment Indirect Addressing: Replaces IPIP and CSCS with four consecutive bytes stored in memory.

    • Example: JMP [5000H] (loads low word from addresses 5000H and 5001H into IPIP, and high word from 5002H and 5003H into CSCS)

8086 Instruction Set Architecture (ISA)

  • 1. Data Transfer Instructions:

    • MOV dest, src: Moves bytes or words between registers, memory, and immediate data. Cannot move memory-to-memory directly or segment-to-segment.

    • XCHG dest, src: Swaps contents between two registers, or a register and memory (reg2 ↔\leftrightarrow reg1, mem ↔\leftrightarrow reg1).

    • PUSH src / POP dest: Decrements SPSP by 2 and pushes 16-bit data; pops data and increments SPSP by 2.

    • IN acc, port: Reads a byte/word into ALAL/AXAX from an 8-bit port address (IN AL, addr8) or indirect 16-bit port in DXDX (IN AX, [DX]).

    • OUT port, acc: Writes a byte/word from ALAL/AXAX to an 8-bit port or indirect port specified in DXDX.

  • 2. Arithmetic Instructions:

    • ADD dest, src: Computes dest←dest+src\text{dest} \leftarrow \text{dest} + \text{src}. Sets all condition flags.

    • ADC dest, src: Computes dest←dest+src+CF\text{dest} \leftarrow \text{dest} + \text{src} + CF.

    • SUB dest, src: Computes dest←dest−src\text{dest} \leftarrow \text{dest} - \text{src}.

    • SBB dest, src: Subtraction with borrow: dest←dest−src−CF\text{dest} \leftarrow \text{dest} - \text{src} - CF.

    • INC dest / DEC dest: Adds or subtracts 1 from register or memory. Updates OF,SF,ZF,AF,PFOF, SF, ZF, AF, PF, but does not affect the Carry Flag (CF).

    • MUL src (Unsigned): For an 8-bit operand, computes AX←AL×reg8/mem8AX \leftarrow AL \times \text{reg8/mem8}. For a 16-bit operand, computes (DX)(AX)←AX×reg16/mem16(DX)(AX) \leftarrow AX \times \text{reg16/mem16}.

    • IMUL src: Signed multiplication with identical register configurations.

    • DIV src (Unsigned): Division of 16-bit dividend in AXAX by 8-bit divisor yields quotient in ALAL and remainder in AHAH. Division of 32-bit dividend in (DX)(AX)(DX)(AX) by 16-bit divisor yields quotient in AXAX and remainder in DXDX.

    • IDIV src: Signed division following the same register allocation.

    • CMP dest, src: Performs internal subtraction (dest−src\text{dest} - \text{src}) and sets flags without modifying destination or source registers:

    • If dest>src\text{dest} > \text{src}: CF=0,ZF=0,SF=0CF = 0, ZF = 0, SF = 0

    • If dest<src\text{dest} < \text{src}: CF=1,ZF=0,SF=1CF = 1, ZF = 0, SF = 1

    • If dest=src\text{dest} = \text{src}: CF=0,ZF=1,SF=0CF = 0, ZF = 1, SF = 0

  • 3. Logical Instructions:

    • AND dest, src: Bitwise logical AND; clears CFCF and OFOF to 0.

    • OR dest, src: Bitwise logical OR; clears CFCF and OFOF to 0.

    • XOR dest, src: Bitwise logical XOR; clears CFCF and OFOF to 0. Frequently used to clear registers (XOR AX, AX).

    • TEST dest, src: Performs bitwise AND without modifying destination; updates flags to test specific bit fields.

    • SHR dest, count: Logical shift right; bits shift right, MSB fills with 00, and the bit shifted out enters CFCF.

    • SHL / SAL dest, count: Logical/Arithmetic shift left; bits shift left, LSB fills with 00, and the bit shifted out enters CFCF.

    • RCR dest, count: Rotate right through Carry Flag; bits rotate right with CFCF acting as the 9th (or 17th) bit.

    • ROL dest, count: Rotate left; bits rotate left, and the MSB bit copies simultaneously into the LSB position and CFCF.

    • Shift/rotate count is either immediate 11, or held in register CLCL if greater than 1.

  • 4. String Manipulation Instructions:

    • Strings are sequential blocks of bytes or words. Source is indexed by DS:SI\text{DS}:\text{SI}, and destination is indexed by ES:DI\text{ES}:\text{DI}.

    • Registers SISI and DIDI are automatically incremented by 1 (byte) or 2 (word) if DF=0DF = 0 (CLD), or decremented by 1 or 2 if DF=1DF = 1 (STD).

    • MOVSB / MOVSW: Move string byte or word from DS:SI\text{DS}:\text{SI} to ES:DI\text{ES}:\text{DI}.

    • CMPSB / CMPSW: Compares byte or word strings by performing internal subtraction and updating condition flags.

    • LODSB / LODSW: Loads string byte from DS:SI\text{DS}:\text{SI} into ALAL (or word into AXAX); auto-updates SISI.

    • STOSB / STOSW: Stores string byte from ALAL (or word from AXAX) into memory location ES:DI\text{ES}:\text{DI}; auto-updates DIDI.

    • Repeat Prefixes: REP (repeats string instruction while CX≠0CX \ne 0, decrementing CXCX each cycle); REPZ / REPE (repeats while CX≠0CX \ne 0 and ZF=1ZF = 1); REPNZ / REPNE (repeats while CX≠0CX \ne 0 and ZF=0ZF = 0).

  • 5. Processor Control Instructions:

    • STC: Set Carry Flag (CF←1CF \leftarrow 1).

    • CLC: Clear Carry Flag (CF←0CF \leftarrow 0).

    • CMC: Complement Carry Flag (CF←CF‾CF \leftarrow \overline{CF}).

    • STD: Set Direction Flag (DF←1DF \leftarrow 1).

    • CLD: Clear Direction Flag (DF←0DF \leftarrow 0).

    • STI: Set Interrupt Flag (IF←1IF \leftarrow 1; enables maskable interrupts).

    • CLI: Clear Interrupt Flag (IF←0IF \leftarrow 0; disables maskable interrupts).

    • NOP: No operation (consumes clock cycles without affecting state).

    • HLT: Halts instruction execution until an external hardware interrupt occurs.

  • 6. Control Transfer Instructions:

    • Unconditional transfer: CALL, RET, JMP.

    • Relative conditional jumps (affecting flags and checking conditions within an 8-bit signed range −128-128 to +127+127 bytes, disp8):

    • Jump if Zero/Equal: JZ / JE (ZF=1ZF = 1

    • Jump if Not Zero/Not Equal: JNZ / JNE (ZF=0ZF = 0

    • Jump if Carry: JC (CF=1CF = 1

    • Jump if No Carry: JNC (CF=0CF = 0

    • Jump if Parity Even: JP / JPE (PF=1PF = 1

    • Jump if Parity Odd: JNP / JPO (PF=0PF = 0

    • Jump if Overflow: JO (OF=1OF = 1

    • Jump if No Overflow: JNO (OF=0OF = 0

    • Jump if Sign (Negative): JS (SF=1SF = 1

    • Jump if Not Sign (Positive): JNS (SF=0SF = 0

    • Unsigned comparisons: JA / JNBE (Above), JAE / JNB (Above or Equal), JB / JNAE (Below), JBE / JNA (Below or Equal).

    • Signed comparisons: JG / JNLE (Greater), JGE / JNL (Greater or Equal), JL / JNGE (Less), JLE / JNG (Less or Equal).

  • Procedure Call and Return Mechanics:

Nested Procedure Calls and Execution Sequence
  • Execution of CALL Proc1 pushes return address (4101H4101\text{H}) onto the stack.

  • Inside Proc1, calling Proc2 at 4600H pushes next return address (4601H4601\text{H}).

  • RETURN instruction pops the top return address (4601H4601\text{H}) into IPIP, returning to Proc1.

  • Subsequent calls and returns track execution dynamically using the stack frame.

Assembly Language Programming (ALP) Algorithms and Implementations

  • Searching for Data in an Array:

    • Searches an array beginning at offset 1200H for target value AB96H. If found, writes its offset address to 1400H; if not found, stores 0000H.

MOV SI, 1200H       ; Initialize SI to start of array
MOV AX, [SI]        ; Load target value into AX
MOV CX, 05H         ; Set loop counter for 5 comparisons
GG12:
INC SI              ; Advance SI by 2 bytes (word size)
INC SI
CMP AX, [SI]        ; Compare target with current element
JE SS               ; If match found, branch to SS
DEC CX              ; Decrement count
JNZ GG12            ; Continue loop if CX != 0
MOV SI, 0000H       ; Value not found, assign 0000H to SI
SS:
MOV [1400H], SI     ; Store matching location or 0000H at 1400H
HLT                 ; Halt
  • Separating Odd and Even Numbers:

    • Scans an array of 6 numbers at 1600H to 1605H, filtering odd values into destination memory starting at 1500H.

MOV CL, 06H         ; Counter = 6 elements
MOV SI, 1600H       ; Source index points to array
MOV DI, 1500H       ; Destination index points to output table
Loop1:
LODSB               ; Load byte from [DS:SI] into AL, auto-increment SI
DEC CL              ; Decrement loop count
ROR AL, 01H         ; Rotate right by 1 bit into Carry Flag
JNB Skip            ; If CF = 0, number is even; jump past store
ROL AL, 01H         ; Restore original odd value
MOV [DI], AL        ; Save odd number to [ES:DI]
INC DI              ; Increment destination pointer
Skip:
CMP CL, 00H         ; Check if all elements evaluated
JNE Loop1           ; Repeat if count > 0
HLT                 ; Terminate execution
  • BCD to Hexadecimal Conversion:

    • Converts an 8-bit packed BCD value at memory 1600H (e.g., 56 BCD) to Hexadecimal (38H or 561056_{10}) and stores it at 1500H.

MOV SI, 1600H       ; Source index = 1600H
MOV DI, 1500H       ; Destination index = 1500H
MOV AL, [SI]        ; Load packed BCD value
MOV AH, AL          ; Copy BCD byte to AH
AND AH, 0FH         ; Mask high nibble: AH contains LSD
MOV BL, AH          ; Save LSD in BL register
AND AL, 0F0H        ; Mask low nibble: AL contains MSD
MOV CL, 04H         ; Set count to 4 bits
ROR AL, CL          ; Shift MSD into lower 4 bits
MOV BH, 0AH         ; Multiplier = 10 (decimal)
MUL BH              ; Multiply MSD by 10 (Result in AX)
ADD AL, BL          ; Add LSD to produce Hex equivalent
MOV [DI], AL        ; Store hex byte at 1500H
HLT                 ; Stop
  • Bubble Sort in Ascending Order:

    • Sorts five 8-bit numbers located from 3000H:4000H in ascending order.

MOV AX, 3000H
MOV DS, AX          ; Set Data Segment
MOV CH, 04H         ; Outer loop counter = n - 1 = 4
L3:
MOV CL, 04H         ; Inner loop counter = 4
MOV SI, 4000H       ; Reset pointer to start of array
L2:
MOV AL, [SI]        ; Read element
MOV AH, [SI+01H]    ; Read next adjacent element
CMP AL, AH          ; Compare adjacent elements
JC L1               ; If AL < AH, already in order
JZ L1               ; If equal, do not swap
MOV [SI+01H], AL    ; Swap elements
MOV [SI], AH
L1:
INC SI              ; Move to next element
DEC CL
JNZ L2              ; Inner loop completion
DEC CH
JNZ L3              ; Outer loop completion
HLT
  • Bitwise Palindrome Checker:

    • Checks whether a 16-bit word at 2300H is symmetrical bitwise. If palindrome, writes FFH to 2500H; otherwise writes 00H.

MOV AX, [2300H]     ; Read 16-bit word
MOV CL, 10H         ; 16-bit counter (16 decimal)
UP:
ROR AX, 1           ; Rotate AX right into Carry
RCL DX, 1           ; Rotate DX left pulling Carry
DEC CL
JNZ UP              ; Repeat 16 times to completely reverse bits
CMP AX, DX          ; Compare reversed word with original
JNZ DOWN            ; If mismatch, branch to DOWN
MOV [2500H], 0FFH   ; Is palindrome: store FFH
JMP EXIT
DOWN:
MOV [2500H], 00H    ; Not palindrome: store 00H
EXIT:
HLT
  • String Reversal and Palindrome Verification via Stack:

    • Reverses a 100-byte (64H64\text{H}) string at 2300H into 2500H using stack operations, verifies palindrome status, and outputs FFH (palindrome) or 00H (non-palindrome) to display port 64H.

MOV SI, 2300H       ; Source pointer
MOV DI, 2500H       ; Destination pointer
MOV CL, 64H         ; 100 bytes
L1:
MOV AL, [SI]
PUSH AX             ; Push each character onto stack
INC SI
DEC CL
JNZ L1
MOV CL, 64H
L2:
POP AX              ; Pop characters in reversed sequence
MOV [DI], AL        ; Save to destination array
INC DI
DEC CL
JNZ L2
MOV SI, 2300H       ; Reset pointers to compare arrays
MOV DI, 2500H
MOV CL, 64H
CLD                 ; Forward direction
REPZ CMPSB          ; Compare strings byte by byte
JNZ L3              ; If mismatch, jump to L3
MOV AL, 0FFH        ; Palindrome confirmed
OUT 64H, AL         ; Output to port 64H
JMP Exit
L3:
MOV AL, 00H         ; Not a palindrome
OUT 64H, AL
Exit:
HLT
  • Binary to Gray Code Conversion:

    • Applies the rule: Gray=Binary⊕(Binary≫1)\text{Gray} = \text{Binary} \oplus (\text{Binary} \gg 1).

MOV SI, 1200H       ; Input location
MOV AX, [SI]        ; Read binary word
MOV BX, [SI]
SHR BX, 01H         ; Shift right by 1 bit
XOR AX, BX          ; AX = AX XOR (AX >> 1)
MOV [1400H], AX     ; Store Gray code at 1400H
HLT
  • Greatest Common Divisor (GCD) Implementation:

    • Computes GCD of two numbers at 2300H and 2302H using the Euclidean division algorithm.

MOV SI, 2300H
MOV DI, 2400H
MOV AX, [SI]        ; First number
MOV BX, [SI+2]      ; Second number
UP:
CMP AX, BX
JE EXIT             ; If equal, GCD is found
JB EXCG             ; If AX < BX, exchange them
UP1:
MOV DX, 0000H       ; Clear DX for division
DIV BX              ; Divide AX by BX (remainder in DX)
CMP DX, 0000H       ; Check remainder
JE EXIT             ; If remainder == 0, BX is GCD
MOV AX, DX          ; Remainder becomes new dividend
JMP UP
EXCG:
XCHG AX, BX         ; Ensure AX > BX
JMP UP1
EXIT:
MOV [DI], BX        ; Store GCD at 2400H
HLT

Interrupt Architecture, IVT, and Exception Handling

  • An interrupt is an event that temporarily suspends the current program sequence to execute an Interrupt Service Routine (ISR), returning upon completion via the IRET instruction.

  • Interrupt Processing Sequence:

Interrupt Processing Flowchart
  • 1. The processor completes execution of the current instruction.

  • 2. The interrupt signal is sampled on INTR\text{INTR} or triggered internally.

  • 3. For maskable interrupts, if IF=0IF = 0, the request is ignored; if IF=1IF = 1, the CPU issues two active-low pulses on INTA‾\overline{\text{INTA}}.

  • 4. The interrupting peripheral supplies an 8-bit interrupt type number (NN) on data lines D0−D7D_0 - D_7 during the second INTA‾\overline{\text{INTA}} cycle.

  • 5. The processor pushes the 16-bit Flag Register onto the stack.

  • 6. Both IFIF and TFTF are cleared to 00, disabling further maskable interrupts and turning off single-stepping.

  • 7. The current Code Segment register (CSCS) is pushed onto the stack.

  • 8. The current Instruction Pointer (IPIP) is pushed onto the stack.

  • 9. The address of the ISR is obtained from the Interrupt Vector Table:

    • Low word from memory address 4×N4 \times N is loaded into IPIP.

    • High word from memory address 4×N+24 \times N + 2 is loaded into CSCS.


  1. The ISR executes until reaching the IRET instruction, which pops IPIP, CSCS, and the original Flag Register from the stack, restoring pre-interrupt state.

  • Interrupt Vector Table (IVT):

Interrupt Vector Table Layout
  • Occupies the lowest 1 KB1\,\text{KB} of system memory (00000H00000\text{H} to 003FFH003\text{FFH}, exactly 1024 bytes).

  • Supports 256 vector entries (numbered 0 to 255). Each vector requires 4 contiguous bytes: the lower 2 bytes specify the ISR offset (IPIP), and the upper 2 bytes specify the segment (CSCS).

  • Allocation Breakdown:

    • Vectors 0 to 4 (Dedicated Processor Interrupts):

      • Type 0 (Divide Error): Triggered automatically if a DIV or IDIV quotient exceeds destination register capacity or division by zero is attempted.

      • Type 1 (Single Step): Generated after every instruction execution when the Trap Flag (TFTF) is set to 11.

      • Type 2 (NMI Pin): Invoked by a positive-edge transition on the external NMI\text{NMI} pin, reserved for critical faults such as impending power failure.

      • Type 3 (Breakpoint): Invoked by the 1-byte opcode INT 3 (CCH); utilized by software debuggers to set execution breakpoints.

      • Type 4 (Overflow): Invoked by the INTO instruction if the Overflow Flag (OFOF) is set.

    • Vectors 5 to 31 (Reserved for System Use):

      • Vectors 08H−0FH08\text{H} - 0\text{FH}: Interfaced with the 8259A Interrupt Controller.

      • Vectors 10H−1FH10\text{H} - 1\text{FH}: Assigned to standard PC BIOS service routines.

    • Vectors 32 to 255 (Available for Users):

      • Vectors 20H−3FH20\text{H} - 3\text{FH}: Utilized by DOS operations.

      • Vectors 40H−FFH40\text{H} - \text{FFH}: Open for user hardware and software applications.

    • Interfacing an Interrupt Vector via 74LS244:

74LS244 Interrupt Vector Interface
  • When an external peripheral requires service, it asserts the INTR\text{INTR} pin high.

  • The CPU responds with active-low INTA‾\overline{\text{INTA}} pulses. An active-low NAND logic gate decodes the condition to drive enable pins E1‾\overline{E_1} and E2‾\overline{E_2} of a 74LS244 octal buffer.

  • The inputs I7−I0I_7 - I_0 of the 74LS244 are hardwired to logic levels representing vector 4CH4C\text{H} (0100 110020100\,1100_2):

    • Bits I6,I3,I2I_6, I_3, I_2 connected to +5 V+5\,\text{V} (logic 1).

    • Bits I7,I5,I4,I1,I0I_7, I_5, I_4, I_1, I_0 connected to ground (logic 0).

  • The buffer drives 4CH4C\text{H} onto data lines D7−D0D_7 - D_0, which the processor reads to index the IVT.

    • Vector Table Lookup and Initialization:

  • Vector Calculation for Type 42H42\text{H}:     Table Pointer=4×42H=108H\text{Table Pointer} = 4 \times 42\text{H} = 108\text{H}

    • Looking up table contents:

      • Byte at 108H=2AH108\text{H} = 2A\text{H} (Offset Low)

      • Byte at 109H=33H109\text{H} = 33\text{H} (Offset High) →Offset=332AH\rightarrow \text{Offset} = 332A\text{H}

      • Byte at 10AH=3CH10A\text{H} = 3C\text{H} (Segment Low)

      • Byte at 10BH=4AH10B\text{H} = 4A\text{H} (Segment High) →Segment=4A3CH\rightarrow \text{Segment} = 4A3C\text{H}

    • Resulting physical address:       PA=(4A3CH×10H)+332AH=4A3C0H+332AH=4D6EAH\text{PA} = (4A3C\text{H} \times 10\text{H}) + 332A\text{H} = 4A3C0\text{H} + 332A\text{H} = 4D6EA\text{H}

  • Initializing Vector 40H40\text{H} in Assembly:     Table Address=4×40H=100H\text{Table Address} = 4 \times 40\text{H} = 100\text{H}

PUSH AX             ; Save modified registers
PUSH DS
MOV AX, 0000H       ; Set DS to segment 0000H (IVT base)
MOV DS, AX
MOV AX, OFFSET isr40
MOV [0100H], AX     ; Store offset of ISR at address 100H-101H
MOV AX, SEGMENT isr40
MOV [0102H], AX     ; Store segment of ISR at address 102H-103H
POP DS              ; Restore registers
POP AX

Bus Arbitration, I/O Interfacing, and the 82C59A Priority Controller

  • I/O Transfer Techniques:

    • Programmed I/O: The processor continuously executes instructions to poll peripheral status; simple to design, but wastes processor execution bandwidth.

    • Interrupt-Driven I/O: Peripherals signal readiness via interrupt lines, freeing the CPU to execute background tasks until service is required.

    • Direct Memory Access (DMA): An external DMA controller transfers data directly between high-speed memory and peripherals without routing bytes through the CPU.

  • Bus Arbitration Methods for I/O Modules:

    • Daisy Chaining:

    • Steps: If bus is not busy, a device asserts the shared Bus Request line. The Master activates the Bus Grant line, which serially propagates through device D1D_1, then D2D_2, then D3D_3. The first requesting device intercepts the grant and asserts the shared Bus Busy line.

    • Advantages: Simple hardware layout; requires only three control lines regardless of device count.

    • Disadvantages: Priority is hardwired based on physical chain placement; poor fault tolerance (a failure in an upstream device breaks the arbitration chain for all downstream devices).

    • Polling Arbitration:

    • Steps: Requesting devices assert the shared Bus Request line. The master polls devices by placing unique device address IDs across kk dedicated polling lines. The identified requesting device responds by seizing the bus and asserting Bus Busy.

    • Advantages: Avoids the serial vulnerability of daisy chains; supports dynamic priority reassignment in software.

    • Disadvantages: Requires additional poll lines; introduces polling delays proportional to the number of attached devices.

    • Independent Request Arbitration:

    • Steps: Each device (D1,D2,D3D_1, D_2, D_3) has an independent Bus Request line (R1,R2,R3R_1, R_2, R_3) and Bus Grant line (G1,G2,G3G_1, G_2, G_3). The master evaluates requests using internal priority logic and asserts the grant line for the chosen device. The selected device asserts Bus Busy.

    • Advantages: Extremely fast arbitration; full dynamic priority programming.

    • Disadvantages: High hardware overhead; requires 2n2n dedicated control lines for nn devices.

  • Intel 82C59A Programmable Interrupt Controller (PIC):

82C59A Cascaded Architecture
  • Acts as an external arbiter managing up to 8 vectored priority interrupts per chip via input pins IR0−IR7IR_0 - IR_7.

  • Cascading Configuration: Multiple 82C59A chips can be arranged in a master/slave hierarchy. A single Master PIC can connect up to 8 Slave PICs via its IRIR lines, expanding system capacity to service up to 8×8=648 \times 8 = 64 peripheral devices connected to a single processor INTR\text{INTR} pin.

  • Programmable Priority Modes:

    • Fully Nested Mode: Default configuration. Interrupt requests are ordered linearly from highest priority at IR0IR_0 down to lowest at IR7IR_7.

    • Rotating Mode: Used when peripherals have equal priority. Once a device at a given IRIR line is serviced, it rotates to become the lowest priority in the group.

    • Special Mask Mode: Allows software to selectively inhibit interrupts from specific devices while permitting interrupts from other channels.

Serial Communication Principles and the RS-232 Protocol Standard

  • Serial vs. Parallel Data Transmission:

    • Parallel Transmission: Transmits a whole byte (8 bits) or word simultaneously across multiple parallel data lines during a single clock pulse. Yields high data rates across short distances, but suffers from wire costs, bulkiness, and inter-line capacitive crosstalk over longer runs.

    • Serial Transmission: Transmits data sequentially, bit by bit, over a single conductor or pair. Highly cost-effective and reliable over long distances.

  • Computer Interfacing Ports Overview:

    • Computer rear I/O panels host diverse interfaces: PS/2 ports for keyboard (purple) and mouse (green); RJ-45 Ethernet port; USB ports (Type-A, Type-B, Type-C, Mini, Micro); 15-pin 3-row high-density blue VGA port for monitors; 25-pin female DB-25 LPT1 parallel port for printers; 9-pin male DB-9 serial COM port; 15-pin 2-row yellow Game port for joysticks; and 3.5mm analog audio jacks (Line-In, Microphone, Speakers).

  • RS-232 Protocol Overview:

    • Standard protocol established for asynchronous serial data exchange between Data Terminal Equipment (DTE, such as computers or transmitters) and Data Communication Equipment (DCE, such as modems or receivers).

    • Standard operating limits: operational over cable distances up to 50 feet50\,\text{feet} at data rates up to 1.492 kbps1.492\,\text{kbps} (and higher over shorter distances).

    • Requires a common signal ground between DTE and DCE. Highly sensitive to induced line noise and crosstalk at higher baud rates.

    • Voltage levels (+3 V+3\,\text{V} to +15 V+15\,\text{V} for logic 0/space; −3 V-3\,\text{V} to −15 V-15\,\text{V} for logic 1/mark) are fundamentally incompatible with standard 0 V/+5 V0\,\text{V} / +5\,\text{V} TTL/CMOS logic, requiring hardware level converters (e.g., MAX232).

  • Flow Control and Handshaking Mechanisms:

    • No Handshaking: The receiver must read each incoming bit or character from its 1-bit or 1-byte receiver buffer before the transmitter delivers the next unit. If the receiver CPU is delayed, the unread buffer contents are overwritten, resulting in buffer overrun and data loss.

    • Hardware Handshaking (RTS/CTS & DTR/DSR):

    • Transmit flow is regulated by physical control lines:

      • RTS (Ready to Send): Driven high by DTE to indicate it wishes to transmit.

      • CTS (Clear to Send): Driven high by DCE to signal its buffer is empty and ready to accept data.

      • DTR (Data Terminal Ready): Driven by DTE to show it is powered on and operational.

      • DSR (Data Set Ready): Driven by DCE to confirm the modem/peripheral is ready.

      • DCD (Data Carrier Detect): Asserted by DCE upon detecting a valid carrier signal.

      • RI (Ring Indicator): Asserted by DCE upon sensing a telephone ringing signal.

    • RTS/CTS Cycle: When DTE has data, it pulls RTS high and waits. When DCE is ready, it pulls CTS high. The transmitter sends data; if the receiver buffer fills, CTS is pulled low, halting transmission until the buffer is cleared.

    • Software Handshaking (X-ON / X-OFF):

    • Avoids dedicated handshaking wires by embedding special control bytes directly in the data path.

    • When the receiver buffer approaches capacity, it transmits an X-OFF (Transmitter Off) control byte. The transmitter suspends transmission until it receives an X-ON (Transmitter On) control byte.

  • Connector Pin Configurations (DB-9 and DB-25):

RS-232 DB25 Pinout
  • DB-9 Connector Pinout:

    • Pin 1: Carrier Detect (CD / DCD)

    • Pin 2: Receive Data (RxD)

    • Pin 3: Transmit Data (TxD)

    • Pin 4: Data Terminal Ready (DTR)

    • Pin 5: Signal Ground (GND)

    • Pin 6: Data Set Ready (DSR)

    • Pin 7: Request to Send (RTS)

    • Pin 8: Clear to Send (CTS)

    • Pin 9: Ring Indicator (RI)

  • DB-25 Connector Pinout:

    • Pin 1: Protective Ground

    • Pin 2: Transmitted Data (TxD / TD)

    • Pin 3: Received Data (RxD / RD)

    • Pin 4: Request to Send (RTS)

    • Pin 5: Clear to Send (CTS)

    • Pin 6: Data Set Ready (DSR)

    • Pin 7: Signal Ground / Common Return (GND)

    • Pin 8: Received Line Signal Detector (DCD)

    • Pin 9: +Voltage+\text{Voltage}

    • Pin 10: −Voltage-\text{Voltage}

    • Pin 11: Unassigned

    • Pin 12: Secondary DCD

    • Pin 13: Secondary CTS

    • Pin 14: Secondary Transmitted Data

    • Pin 15: DCE Transmitter Clock (Tx-CLK)

    • Pin 16: Secondary Received Data

    • Pin 17: Receiver Clock (Rx-CLK)

    • Pin 18: Local Loopback

    • Pin 19: Secondary RTS

    • Pin 20: Data Terminal Ready (DTR)

    • Pin 21: Signal Quality Detector / Remote Loopback

    • Pin 22: Ring Indicator (RI)

    • Pin 23: Data Signal Rate Selector

    • Pin 24: DTE Transmitter Clock (Tx-CLK)

    • Pin 25: Test Mode

    • Asynchronous Framing and Bit-Level Character Transmission:

RS-232 Character Frame for ASCII 'A'
  • In asynchronous transmission, the serial line idles in the marking state (logic 1).

  • Frame Structure:

    • Start Bit: A single transition to logic 0 (space) signaling the receiver to synchronize its clock.

    • Data Bits: 5 to 8 bits transmitted LSB first (b0b_0 through b6b_6 or b7b_7).

    • Parity Bit: Optional bit appended for error detection, set to ensure an even or odd count of logic 1s.

    • Stop Bits: 1, 1.5, or 2 bits at logic 1 (mark) defining the end of the frame.

  • Framing Error: If the receiver detects a logic 0 when a stop bit (logic 1) is expected, a framing error is flagged, indicating clock desynchronization.

  • Worked Decoding Example for the Character Stream 'AppLe':

    • Configuration: ASCII encoding, even parity, 2 stop bits.

    • Serial Bitstream: 11111010000010110000011111111111111000001111111100011001111010100110111111111

    • Character 1 ('A'):

    • Inactive line: 11111

    • Start bit: 0

    • Data bits (LSB first): 1000001 (binary 10000012=41H=65101000001_2 = 41\text{H} = 65_{10}, which represents ASCII 'A')

    • Parity bit: 0 (total 1s in data is 2; parity bit 0 maintains even parity)

    • Stop bits: 11

    • Character 2 ('p'):

    • Start bit: 0

    • Data bits (LSB first): 0000111 (binary 11100002=70H=112101110000_2 = 70\text{H} = 112_{10}, which represents ASCII 'p')

    • Parity bit: 1 (data contains three 1s; parity bit 1 maintains even parity)

    • Stop bits: 11

    • Character 3 ('p'):

    • Inactive line: 11111111

    • Start bit: 0

    • Data bits: 0000111 (ASCII 'p')

    • Parity bit: 1

    • Stop bits: 11

    • Character 4 ('L'):

    • Inactive line: 11

    • Start bit: 0

    • Data bits (LSB first): 0011001 (binary 10011002=4CH=76101001100_2 = 4C\text{H} = 76_{10}, which represents ASCII 'L')

    • Parity bit: 1 (data contains three 1s; parity bit 1 maintains even parity)

    • Stop bits: 11

    • Complete reconstructed ASCII message: AppLe


Theory Exam Question & Answer

Question: Draw and explain the internal architecture of the Intel 8086 microprocessor. Describe the functions of the Bus Interface Unit (BIU) and Execution Unit (EU).


1. Introduction

The Intel 8086 is a 16-bit16\text{-bit} microprocessor packaged in a 40-pin Dual Inline Package (DIP) with a 20-bit20\text{-bit} address bus (1 MB1\text{ MB} addressable memory) and a 16-bit16\text{-bit} data bus.

Internally, the architecture is partitioned into two independent, concurrently functioning functional blocks:

  1. Bus Interface Unit (BIU)

  2. Execution Unit (EU)

This separation allows the 8086 to implement hardware pipelining, where instruction fetching overlaps with instruction decoding and execution.


2. Architectural Block Diagram


Block Diagram of 8086 Microprocessor

(In an examination, sketch the two major blocks side-by-side: the BIU on top/left with the 4 segment registers, IP, 20-bit adder, and 6-byte queue; and the EU on bottom/right with the general-purpose registers, pointer/index registers, ALU, control unit, and flag register).


3. Bus Interface Unit (BIU)

The BIU handles all data and address transfers across the external system buses for memory and I/O devices.

Key Functions:
  • Generates the 20-bit20\text{-bit} physical memory address.

  • Fetches instruction opcodes from system memory.

  • Reads and writes operands from/to memory and I/O ports.

  • Buffers instructions in an internal pre-fetch queue.

Functional Components of BIU:
  1. Instruction Pre-fetch Queue (6-Byte6\text{-Byte} FIFO):

    • Implemented as a First-In, First-Out register array.

    • While the EU is decoding or executing an instruction, the BIU utilizes idle bus cycles to prefetch up to 6 bytes6\text{ bytes} of instruction code sequentially from memory.

    • Eliminates instruction fetch latency, keeping the EU continuously supplied.

  2. Segment Registers (16-bit16\text{-bit} each):

    • Code Segment (CSCS): Holds the base address of the current 64 KB64\text{ KB} code segment where program instructions reside.

    • Data Segment (DSDS): Points to the base of the data segment holding program variables and constants.

    • Stack Segment (SSSS): Points to the memory segment allocated for stack operations and return addresses.

    • Extra Segment (ESES): Provides an additional data segment, notably used for destination strings in string instructions.

  3. Instruction Pointer (IPIP, 16-bit16\text{-bit}):

    • Contains the offset address of the next sequential instruction byte to be fetched from the Code Segment (CS:IPCS:IP).

    • Automatically incremented by the BIU after every fetch and modified during branch, call, and jump instructions.

  4. 20-bit20\text{-bit} Dedicated Address Adder:

    • Calculates the 20-bit20\text{-bit} physical address (PAPA) from a 16-bit16\text{-bit} segment base and a 16-bit16\text{-bit} offset using:      Physical Address=(Segment Register×10H)+Offset\text{Physical Address} = (\text{Segment Register} \times 10\text{H}) + \text{Offset}

  5. Bus Control Logic:

    • Drives bus control signals (such as RD‾\overline{\text{RD}}, WR‾\overline{\text{WR}}, ALE\text{ALE}, and M/IO‾\text{M}/\overline{\text{IO}}) to coordinate bus transactions.


4. Execution Unit (EU)

The EU is completely isolated from the system buses and is responsible for decoding and executing instructions supplied by the BIU queue.

Key Functions:
  • Receives opcodes from the BIU FIFO queue.

  • Decodes instructions using the internal control unit.

  • Coordinates operand retrieval from general registers.

  • Performs arithmetic and logic operations via the ALU.

  • Updates status and control flags based on operation results.

Functional Components of EU:
  1. Control Unit & Instruction Decoder:

    • Fetches opcodes from the queue, decodes them, and generates internal control signals to route data through the ALU and registers.

  2. Arithmetic Logic Unit (ALU, 16-bit16\text{-bit}):

    • Capable of performing 8-bit8\text{-bit} and 16-bit16\text{-bit} arithmetic (ADDADD, SUBSUB, MULMUL, DIVDIV) and logical (ANDAND, OROR, XORXOR, shift, rotate) operations.

  3. General-Purpose Registers (16-bit16\text{-bit} each):

    • Can be used as full 16-bit16\text{-bit} registers or addressed as pairs of 8-bit8\text{-bit} registers (High and Low):

      • AXAX (AHAH, ALAL) - Accumulator: Preferred for arithmetic/logical instructions; produces the most compact machine code; mandatory for hardware multiplication, division, and direct I/O.

      • BXBX (BHBH, BLBL) - Base Register: Commonly used to store base offset memory pointers.

      • CXCX (CHCH, CLCL) - Count Register: Used as an automatic loop counter (LOOP) and shift/rotate bit counter (CLCL).

      • DXDX (DHDH, DLDL) - Data Register: Holds high-order bits during 32-bit32\text{-bit} multiplication/division and holds port addresses in indirect I/O instructions.

  4. Pointer and Index Registers (16-bit16\text{-bit} each, accessible only as full words):

    • Stack Pointer (SPSP): Stores the offset address of the current top of the stack (SS:SPSS:SP).

    • Base Pointer (BPBP): Accesses data and parameters located within the stack frame (SS:BPSS:BP).

    • Source Index (SISI): Serves as an offset pointer in data segment accesses and acts as the source string offset (DS:SIDS:SI).

    • Destination Index (DIDI): Serves as an offset pointer and destination string offset (ES:DIES:DI).

  5. Flag Register (16-bit16\text{-bit}):

    • Contains 99 active flags:

      • 6 Status/Conditional Flags: Carry Flag (CFCF), Parity Flag (PFPF), Auxiliary Carry Flag (AFAF), Zero Flag (ZFZF), Sign Flag (SFSF), and Overflow Flag (OFOF).

      • 3 Control Flags: Trap Flag (TFTF for single-stepping), Interrupt Enable Flag (IFIF), and Direction Flag (DFDF for string auto-indexing).


5. Pipelining in the 8086
  • In earlier processors like the 8085, the fetch, decode, and execute stages occurred strictly in serial sequence.

  • In the 8086, the BIU and EU operate in parallel. While the EU is executing an instruction, the BIU uses idle bus cycles to prefetch upcoming instructions into the 6-byte FIFO queue.

  • Consequently, the fetch cycle is overlapped with the execution cycle, minimizing instruction execution latency.