Comprehensive Study Guide: Intel 8086 Microprocessor Architecture, Interfacing, and Instruction Set
Overview of Computer Systems and Microprocessor Evolution
Basic Computer System Architecture:
Central Processing Unit (CPU): Contains the Control Unit (CU) and Arithmetic/Logic Unit (ALU).
Control Unit (CU): Decodes instructions and manages the timing and control signals of the entire computer system.
Arithmetic/Logic Unit (ALU): Executes mathematical operations (addition, subtraction, multiplication, division) and logical operations (AND, OR, XOR, shifts).
Memory Unit (MU): Primary storage holding executable instructions and active data.
Input and Output Devices: Peripherals providing data input to the CPU and displaying or outputting processed results.

Evolutionary History of Intel Microprocessors:
8085: microprocessor architecture.
8086: First microprocessor architecture.
80186: Enhanced microprocessor with integrated hardware peripherals.
80286: processor introducing protected mode operation and expanded memory management.
80386: First processor architecture supporting paging and virtual memory.
80486: processor incorporating an on-chip floating-point unit (FPU) and L1 cache.
80586 / Pentium Series: Advanced superscalar architecture progressing through Pentium 1 (P1), Pentium 2 (P2), Pentium 3 (P3), Core 2 Duo (C2D), Core i7 (Ci7), and Core i9 (Ci9).
Comparative Analysis: Intel 8085 vs. Intel 8086:
Data Bus / Processor Size:
8085: size.
8086: size.
Address Bus Width:
8085: address bus.
8086: address bus.
Addressable Memory Capacity:
8085: Address space of .
8086: Address space of .
Instruction Prefetch Queue:
8085: No instruction queue.
8086: Contains a instruction prefetch queue.
Pipelining Capabilities:
8085: Does not support instruction pipelining.
8086: Supports instruction pipelining (Fetch Stage and Execution Stage operating concurrently).
I/O Ports Capacity:
8085: addressable I/O ports.
8086: addressable I/O ports.
Relative Unit Cost:
8085: Low cost.
8086: High cost.
8086 Microprocessor Architecture and Components
General Specifications of Intel 8086:
Designed by Intel in 1976 and commercially released in 1978 (Intel D8086).
Fully architecture featuring a ALU, internal registers, and a data bus.
physical address bus allowing access to () of memory space.
() input/output port space.
Contains 14 internal registers, each wide.
Available in three speed versions: , , and .
Driven by a single-phase clock with a duty cycle.
Integrated vector table supporting 256 vectored interrupts.
Operates in two hardware configurations: Minimum Mode (single-processor configuration) and Maximum Mode (multiprocessor/coprocessor configuration).

Internal Functional Division:
The internal architecture is partitioned into two functional units working in parallel: the Bus Interface Unit (BIU) and the Execution Unit (EU).
Bus Interface Unit (BIU):
Primary Functions:
Fetches instruction bytes from memory.
Calculates physical memory addresses.
Manages data transfers between CPU registers and external memory or I/O ports.
Controls the instruction prefetch queue to maintain pipelining.
Core Components of BIU:
Segment Registers: Four dedicated base registers:
Code Segment Register (
CS)Data Segment Register (
DS)Stack Segment Register (
SS)Extra Segment Register (
ES)
Instruction Pointer (
IP): A pointer register containing the offset address of the next instruction byte to be fetched.Address Generation Circuit: A dedicated summation adder () that computes physical addresses from segment base values and offset values.
Instruction Prefetch Queue: A FIFO (First-In, First-Out) queue buffer storing prefetched instruction bytes fetched during idle bus cycles.
Execution Unit (EU):
Primary Functions:
Decodes instruction opcodes drawn from the prefetch queue.
Executes decoded instructions via the internal ALU.
Performs internal register data transfers and arithmetic/logic operations.
Sends requests to the BIU when access to memory or external I/O is required.
Operates in synchronization with clock cycles (T-states).
Core Components of EU:
General Purpose Registers (GPRs): Four registers usable as full words or as independent high (
H) and low (L) byte registers:AX(AH,AL): Accumulator Register.BX(BH,BL): Base Register (can hold memory base offsets).CX(CH,CL): Count Register (used as loop counter and shift/rotate counter).DX(DH,DL): Data Register (holds I/O port addresses and multiplication/division operands).
Pointer and Index Registers: Four registers used to hold segment offset displacements:
Stack Pointer (
SP): Holds top-of-stack offset in Stack Segment.Base Pointer (
BP): Holds offset address in Stack Segment for parameter passing.Source Index (
SI): Holds offset of source operand in Data Segment.Destination Index (
DI): Holds offset of destination operand in Extra Segment.
Arithmetic Logic Unit (ALU): execution unit performing addition, subtraction, multiplication, division, AND, OR, XOR, shifts, and rotates.
Flag Register: register holding processor status and control flags.
Flag Register Structure and Status Definitions
Bit Layout of the 16-Bit Flag Register:
Contains 9 active flags (6 Status Flags and 3 Control Flags). Unused bit positions are marked as don't-care (
x).

Status Flags:
Carry Flag (CF):
: A carry out of the most significant bit (MSB) occurred during addition, or a borrow was required during subtraction.
: No carry or borrow occurred out of the MSB.
Parity Flag (PF):
: Lower 8 bits of the operation result contain an even number of 1s (Even Parity).
: Lower 8 bits contain an odd number of 1s (Odd Parity).
Auxiliary Carry Flag (AF):
: A carry occurred from the lower nibble (bit 3) to the higher nibble (bit 4) in arithmetic.
: No carry across the nibble boundary. Primarily utilized in BCD (Binary Coded Decimal) routines.
Zero Flag (ZF):
: The result of an arithmetic or logical operation equals zero.
: The result is non-zero.
Sign Flag (SF):
: The MSB of the result is 1, indicating a negative signed value.
: The MSB of the result is 0, indicating a positive signed value.
Overflow Flag (OF):
: An arithmetic overflow occurred, meaning the signed result exceeded the storage capacity of the destination operand.
: No signed overflow occurred.
Control Flags:
Trap Flag (TF):
: Puts the processor into Single-Stepping mode. The CPU automatically generates an internal
INT 1interrupt after executing each instruction, enabling step-by-step debugging.: Disables single-stepping execution.
Interrupt Flag (IF):
: Enables recognition of maskable hardware interrupt requests received on the
INTRpin.: Disables maskable
INTRinterrupts.
Direction Flag (DF):
: Auto-decrements index registers (
SIandDI) during string processing instructions.: Auto-increments index registers (
SIandDI) during string instructions.
Memory Segmentation and Address Calculation
Physical Address Generation:
Because segment registers and offset registers are wide, the BIU combines a segment base address with a offset address using a bit-shift adder circuit to generate a physical address.
Address Calculation Formula:
Equivalently, the segment register value is shifted left by 4 binary bit positions () and added to the offset displacement.

Worked Physical Address Calculation Example:
Given Segment Register Value =
Given Offset Displacement =
Shift Segment Register left by 4 bits:
Add Offset Value: \begin{array}{r@{\quad}l} & 53C20_{\text{H}} \\ + & 107A_{\text{H}} \\ \hline = & 54C9A_{\text{H}} \end{array}
Calculated Physical Address = .
Concept of Memory Segmentation:
Segmentation is the division of the physical memory space into logical blocks called segments.
Each logical segment has a maximum size of (), matching the addressable range of a offset register ( to ).
Active Segments and Register Pairings:
Code Segment (
CS): Holds instruction code. Paired withIPto generate physical code address: .Stack Segment (
SS): Holds stack data. Paired withSP(top of stack) orBP(stack base offset): .Data Segment (
DS): Holds program variables. Paired withBX,SI, or direct offset: .Extra Segment (
ES): Holds extra destination data for string instructions. Paired withDI: .
Segment Access Status Lines ():
: Extra Segment Access.
: Stack Segment Access.
: Code Segment Access.
: Data Segment Access.
Advantages of Memory Segmentation:
Enables registers to address of physical memory.
Separates instruction code, data variables, and stack frames into isolated segments, enhancing code integrity and security.
Facilitates relocatable code: programs can be loaded anywhere in physical memory by changing segment base registers without reassembling logical offsets.
Memory Banking in 8086
Concept of Memory Banking:
The physical memory space is organized as two parallel memory banks: the Even Bank (Lower Bank) and the Odd Bank (Higher Bank).
Even Bank (Lower Bank - LB): Stores bytes located at even physical memory addresses (). Connected to lower data lines . Activated when address line A_0 = 0$.\n * **Odd Bank (Higher Bank - HB)**: Stores bytes located at odd physical memory addresses (00001_{\text{H}}, 00003_{\text{H}}, 00005_{\text{H}}, \dotsD_8 - D_{15}\overline{\text{BHE}} = 0$.
Banking Operation Control Matrix:
: Read or write a word in a single bus cycle from both banks simultaneously (Aligned Word Access).
: Read or write an byte from/to the higher odd memory bank.
: Read or write an byte from/to the lower even memory bank.
: No memory operation (Processor bus is idle).
Aligned vs. Misaligned Memory Access:
Aligned Word Operation: A word stored at an even starting address (e.g.,
MOV BX, [2000H]). The CPU fetches both bytes simultaneously in 1 bus cycle because the lower byte is in the Even Bank and the upper byte is in the Odd Bank.Misaligned Word Operation: A word stored starting at an odd address (e.g.,
MOV BX, [2001H]). Access requires 2 bus cycles:First Bus Cycle: Fetches the lower byte from odd address using the Higher Bank ().
Second Bus Cycle: Fetches the upper byte from even address using the Lower Bank ().
8086 Pin Description and Demultiplexing
Pin Configuration Overview:
Housed in a 40-pin Dual In-line Package (DIP).

Common Signal Pin Descriptions (Pins 1–23 and 32–40):
(Pin 40): Power supply input ().
(Pins 1 and 20): System ground connections.
(Pins 16–2, 39): Multiplexed bidirectional address/data bus lines.
During clock state, lines carry lower of physical address ().
During clock states, lines carry of parallel data ().
carries lower byte (); carries upper byte ().
(Pins 38–35): Multiplexed unidirectional address/status bus lines.
During , lines carry upper 4 bits of physical address ().
During , lines carry status signals S_3, S_4, S_5, S_6$.\n * S_5 indicates the current state of the Interrupt Flag (`IF`).\n * S_6 is always low when 8086 controls the system bus.\n * \overline{ ext{BHE}}/S_7S_7\overline{ ext{BHE}} = 0T_1D_8 - D_{15}).\n * \overline{ ext{RD}} (Pin 32): Read control signal (Active Low). Indicates CPU is reading data from memory or I/O.\n * \overline{ ext{TEST}} (Pin 23): Input signal monitored by `WAIT` instruction. Connected to the `BUSY` output pin of 8087 math coprocessor. If low, execution continues; if high, CPU enters wait states.\n * \text{READY}T_W) into the bus cycle.\n * \text{RESET} (Pin 21): Active high system reset input. Must remain high for at least 4 clock cycles to terminate current activities and re-initialize CPU.\n * ext{CLK}33\% duty cycle ($5\,\text{MHz}, 8\,\text{MHz}, 10\,\text{MHz}).
(Pin 18): Active high, level-triggered maskable interrupt request input line.
(Pin 17): Active high, edge-triggered non-maskable interrupt request input line.
(Pin 33): Mode Select input pin. Connected to () for Minimum Mode; connected to Ground () for Maximum Mode.
Interfacing and Demultiplexing Hardware Support Chips:
8282 8-Bit Octal Latch:
Used to demultiplex and latch physical address lines () and from the multiplexed and buses.
Latching is controlled by Address Latch Enable () connected to the
STBpin of 8282. WhenSTB() is high, input addresses are passed to outputs; when low, outputs hold latched address stable.To latch 21 bus signals ( and ), three 8282 chips () are connected in parallel.
8286 8-Bit Bidirectional Transceiver:
Acts as a bus buffer/driver to separate data from multiplexed buses and increase current drive capability.
Enabled when Data Enable () connected to is low.
Data direction is governed by Data Transmit/Receive () connected to
T: if , data is transmitted out; if , data is received in.Two 8286 chips are required to handle the data bus ().
8284 Clock Generator:
Generates a symmetric clock signal with duty cycle using a quartz crystal oscillator connected across
Generates synchronized system
RESETpulses.Synchronizes asynchronous
READYsignals from slow peripheral devices to the CPU clock.
System Configurations: Minimum Mode and Maximum Mode
Minimum Mode Configuration ():
Configured by pulling pin 33 () high to .
Designed for single-processor systems where 8086 directly generates all bus control signals.
Clock, RESET, and READY signals are supplied by the 8284 clock generator.
External 3-to-8 decoder (74LS138) decodes control outputs to produce , , , and .

Minimum Mode Specific Pin Definitions (Pins 24–31):
(Pin 31): Active high input from DMA controller requesting system bus mastership.
(Pin 30): Hold Acknowledge active high output to DMA controller indicating bus release.
(Pin 29): Write signal active low output. Indicates write operation to memory or I/O.
(Pin 28): Memory/IO select output. High indicates memory access; low indicates I/O port access.
(Pin 27): Data Transmit/Receive output controlling 8286 transceiver data flow. High = Transmit; Low = Receive.
(Pin 26): Data Enable active low output enabling 8286 transceivers.
(Pin 25): Address Latch Enable active high output pulse generated during to latch address into 8282 latches.
(Pin 24): Interrupt Acknowledge active low output signal.
Maximum Mode Configuration ():
Configured by grounding pin 33 ().
Designed for multiprocessor systems incorporating numerical coprocessors (8087) or I/O processors (8089).
An external 8288 Bus Controller chip is required to decode processor status outputs () and generate system control bus signals (, , , , , , , , , ).
Maximum Mode Specific Pin Definitions (Pins 24–31):
and (Pins 31 and 30): Bidirectional Request/Grant pins used by other bus master processors to request system bus access. has higher priority than .
(Pin 29): Active low bus lock output signal activated by adding
LOCKprefix to instructions. Prevents other coprocessors from gaining control of system bus during critical memory cycles.(Pins 28, 27, 26): Status lines output to 8288 Bus Controller:
: Interrupt Acknowledge
: Read I/O Port
: Write I/O Port
: Halt
: Opcode Fetch (Instruction Fetch)
: Memory Read
: Memory Write
: Passive / Inactive
(Pins 25 and 24): Instruction Queue Status outputs reflecting prefetch queue activity:
: No operation
: First byte of opcode fetched from queue
: Prefetch queue is empty
: Subsequent byte fetched from queue
Bus Cycle Timing Diagrams
Fundamental Timing Definitions:
T-State: The duration of one system clock period ().
At clock: .
At clock: .
At clock: .
Bus / Machine Cycle: The total time required to execute one basic read or write memory/IO transfer cycle. Consists of a minimum of 4 clock T-states ().
Read/Write Bus Cycle duration at : .
Read/Write Bus Cycle duration at : .
Read/Write Bus Cycle duration at : .
Instruction Cycle: Total time required to fetch, decode, and execute a complete instruction, composed of one or more consecutive bus cycles.
Minimum Mode Read Cycle Timing Sequence:
: pulse goes high. Address ( and ) and are output on multiplexed bus. is set high (Memory) or low (I/O). is set low (Receive).
: drops low to latch address in 8282. float to high-impedance state. Upper address lines switch to status (). signal drops low. drops low to enable 8286 transceiver.
: Memory or I/O device places data () onto bus lines. Processor samples
READYpin.: Processor latches data byte/word. and return high to end cycle.

Minimum Mode Write Cycle Timing Sequence:
: pulse goes high, outputting address and . indicates memory or I/O access. goes high (Transmit).
: goes low. 8086 outputs write data () onto $AD_0 - AD_{15}\overline{ ext{WR}}\overline{ ext{DEN}} drop low.\n * T_3: Data is maintained stable on bus while external memory/device writes data. Processor samples `READY` pin.\n * T_4\overline{ ext{WR}}\overline{ ext{DEN}} return high, ending cycle.\n\n\n\n* **Maximum Mode Read and Write Cycle Timing Sequences**:\n * Timing structure follows T_1 - T_4 clock states.\n * In T_1\overline{S_2}, \overline{S_1}, \overline{S_0}T_3.\n * Control signals (\overline{ ext{MRDC}}\overline{ ext{IORC}}\overline{ ext{MWTC}}\overline{ ext{AMWTC}}\overline{ ext{IOWC}}\overline{ ext{AIOWC}}\text{ALE}\text{DEN}DT/\overline{ ext{R}}) are produced by the 8288 Bus Controller.\n\n\n\n\n\n# 8086 Interrupt Structure and Servicing\n\n* **Definition and Overview**:\n * An interrupt is an event that suspends normal program execution and redirects CPU control to an Interrupt Service Routine (ISR).\n * The 8086 handles 256 vector interrupts, numbered `INT 0` through `INT 255`.\n\n* **Interrupt Vector Table (IVT)**:\n * Located at the lowest 1\,\text{KB}00000_{\text{H}}003FF_{\text{H}}).\n * **IVT Memory Size Calculation**: 256\text{ interrupts} \times 4\text{ bytes per vector} = 1024\text{ bytes} = 1\,\text{KB}.\n * Each interrupt vector entry requires 4 memory locations:\n * Lower 2 bytes hold the offset address (`IP`): IP_{Lower}N \times 4IP_{Higher}N \times 4 + 1$.
Upper 2 bytes hold the segment address (
CS): at location , at N \times 4 + 3$.\n * **Base Address Formula**: \text{IVT Address} = N \times 4.\n\n\n\n* **Classification of Interrupts**:\n 1. **Dedicated Interrupts (`INT 0` to `INT 4`)**:\n * `INT 0` (Divide Error): Automatically triggered when division quotient exceeds register capacity or when division by zero occurs. IVT Address = 00000_{\text{H}}.\n * `INT 1` (Single Step): Executed after every instruction if Trap Flag TF = 100004_{\text{H}}.\n * `INT 2` (Non-Maskable Interrupt - NMI): Hardware interrupt triggered by an active-high edge on `NMI` pin. IVT Address = 00008_{\text{H}}.\n * `INT 3` (Breakpoint): Caused by opcode `INT 03H` (or single-byte `INT`). Used in debugging large programs to display register contents. IVT Address = 0000C_{\text{H}}.\n * `INT 4` (Overflow - INTO): Triggered by `INTO` instruction if Overflow Flag OF = 100010_{\text{H}}.\n 2. **Reserved Interrupts (`INT 5` to `INT 31`)**: Reserved by Intel for higher processors (80386, Pentium). Not available for general user applications.\n 3. **User Defined Interrupts (`INT 32` to `INT 255`)**: Software interrupts programmed by users for custom application subroutines. Invoked via `INT n` instruction.\n\n* **Hardware Interrupt Signals (`NMI` and `INTR`)**:\n * `NMI`: Non-maskable, high priority, edge-triggered hardware interrupt. Forces CPU to execute `INT 2` service routine.\n * `INTR`: Maskable, low priority, level-triggered hardware interrupt. Masked by clearing Interrupt Flag (IF = 0IF = 1\overline{ ext{INTA}} pulses:\n * *First \overline{ ext{INTA}} Pulse*: Informs peripheral device (e.g., 8259 PIC) to prepare vector number.\n * *Second \overline{ ext{INTA}}NNN \times 4, and fetches target CS:IP from IVT.\n\n* **Interrupt Servicing Sequence (Step-by-Step Procedure)**:\n 1. PUSH Flag Register onto Stack:\n \text{SS}:[\text{SP}-1] \leftarrow \text{Flag}{High}, \quad \text{SS}:[\text{SP}-2] \leftarrow \text{Flag}{Low}, \quad \text{SP} \leftarrow \text{SP} - 2\n 2. Clear Interrupt Flag (`IF`) and Trap Flag (`TF`) (IF \leftarrow 0, TF \leftarrow 0) to disable further maskable interrupts and single stepping.\n 3. PUSH Code Segment (`CS`) onto Stack:\n \text{SS}:[\text{SP}-1] \leftarrow \text{CS}{High}, \quad \text{SS}:[\text{SP}-2] \leftarrow \text{CS}{Low}, \quad \text{SP} \leftarrow \text{SP} - 2\n 4. PUSH Instruction Pointer (`IP`) onto Stack:\n \text{SS}:[\text{SP}-1] \leftarrow \text{IP}{High}, \quad \text{SS}:[\text{SP}-2] \leftarrow \text{IP}{Low}, \quad \text{SP} \leftarrow \text{SP} - 2\n 5. Load new `IP` from IVT address N \times 4N \times 4 + 1$.
Load new
CSfrom IVT address and N \times 4 + 3$.\n 7. Jump control to starting address of ISR routine.\n\n* **Interrupt Return Sequence (`IRET` Execution)**:\n 1. Restore `IP` from Stack (\text{IP} \leftarrow \text{SS}:[\text{SP}], \text{SP} \leftarrow \text{SP} + 2).\n 2. Restore `CS` from Stack (\text{CS} \leftarrow \text{SS}:[\text{SP}], \text{SP} \leftarrow \text{SP} + 2).\n 3. Restore Flag Register from Stack (\text{Flag} \leftarrow \text{SS}:[\text{SP}], \text{SP} \leftarrow \text{SP} + 2).\n\n* **Interrupt Priorities**:\n * **Simultaneous Occurrence Priority**:\n 1. Divide Error, `INT n`, `INTO` (Highest Priority)\n 2. `NMI` (Priority 2)\n 3. `INTR` (Priority 3)\n 4. Single Stepping (`TF`) (Lowest Priority)\n * **Ability to Interrupt Another Running ISR**:\n * Software interrupts (`INT n`) and `NMI` are non-maskable and can interrupt any running ISR.\n * `INTR` and Single Stepping cannot interrupt an executing ISR because IFTF are automatically cleared to 0 upon entering any ISR.\n\n# Data and I/O Addressing Modes\n\n* **Definition**: Addressing modes represent the different methods used by instructions to specify source and destination operand data or effective memory locations.\n\n* **Data Addressing Modes**:\n 1. **Immediate Addressing Mode**: Source operand is an 8-bit or 16-bit constant data value specified within the instruction. Destination cannot be immediate data.\n * `MOV CX, 2000H` (Loads 2000_{\text{H}} into `CX`)\n * `MOV CL, 0AH` (Loads 0\text{A}{\text{H}} into `CL`)\n * `ADD CL, 45H` (Adds 45{\text{H}} to `CL`)\n 2. **Register Addressing Mode**: Both source and destination operands are internal CPU registers.\n * `MOV CL, DL` (Copies contents of `DL` to `CL`)\n * `XOR AX, BX` (Logical XOR between `AX` and `BX`)\n * `ADD AL, BL` (Adds `BL` to `AL`)\n 3. **Direct Addressing Mode**: Effective address (offset) of memory operand is directly specified inside square brackets `[...]` as a displacement value.\n * `MOV CL, [2000H]`\n * *Address Calculation*: \text{PA} = \text{DS} \times 10_{\text{H}} + 2000_{\text{H}}\text{DS} = 5000_{\text{H}}\text{PA} = 50000_{\text{H}} + 2000_{\text{H}} = 52000_{\text{H}}52000_{\text{H}} is moved to `CL`.\n 4. **Indirect Addressing Modes**:\n * **Register Indirect Addressing Mode**: Offset address is stored inside a base or index register (`BX`, `BP`, `SI`, `DI`).\n * `MOV CL, [BX]` (\text{PA} = \text{DS} \times 10_{\text{H}} + \text{BX})\n * **Register Relative Addressing Mode**: Offset is computed as the sum of a register content and a constant displacement.\n * `MOV CL, [BX + 4]` or `MOV CL, 04H[BX]`\n * **Base Indexed Addressing Mode**: Offset is computed as the sum of a base register (`BX` or `BP`) and an index register (`SI` or `DI`). `BX` uses Data Segment (`DS`); `BP` uses Stack Segment (`SS`).\n * `MOV CL, [BX + SI]` (\text{PA} = \text{DS} \times 10_{\text{H}} + \text{BX} + \text{SI})\n * `MOV CL, [BP + SI]` (\text{PA} = \text{SS} \times 10_{\text{H}} + \text{BP} + \text{SI})\n * **Base Relative Plus Indexed Addressing Mode**: Offset is computed as the sum of a base register, index register, and constant displacement.\n * `MOV CL, [BX + DI + 20H]` (Operates in Data Segment)\n * `MOV [BP + SI + 2000H], CL` (Operates in Stack Segment)\n 5. **Implied / Implicit Addressing Mode**: Operands are implicitly defined by the instruction opcode itself.\n * `STC` (Sets Carry Flag CF = 1)\n * `CLD` (Clears Direction Flag DF = 0)\n\n* **I/O Addressing Modes**:\n 1. **Direct I/O Addressing Mode**: Uses an 8\text{-bit}00_{\text{H}}\text{FF}{\text{H}}) specified in instruction, accessing up to 256 I/O port locations.\n * `IN AL, 80H` (Reads byte from I/O port 80{\text{H}} into `AL`)\n * `OUT 05H, AL` (Outputs byte in `AL` to I/O port 05_{\text{H}})\n 2. **Indirect I/O Addressing Mode**: Uses a 16\text{-bit}0000_{\text{H}}\text{FFFF}{\text{H}}), accessing up to 65,536 I/O ports.\n * `MOV DX, 2000H` followed by `IN AL, DX` (Reads byte from I/O port 2000{\text{H}} held in `DX` into `AL`)\n\n# Assembler Directives\n\n* **Definition**: Assembler directives are reserved keywords and statements that direct the assembler during code processing, segment organization, and variable allocation. They do not generate executable machine opcodes.\n\n* **Summary of Key Directives**:\n * `.MODEL`: Defines memory model size:\n * `SMALL`: Code and data fit into single 64\,\text{KB} segments.\n * `MEDIUM`: Multiple code segments (> 64\,\text{KB}64\,\text{KB}).\n * `LARGE`: Multiple code segments and multiple data segments (> 64\,\text{KB}).\n * `.DATA`: Initializes and marks the start of the Data Segment.\n * `.CODE`: Marks the start of the Code Segment.\n * `.STACK`: Initializes and marks the start of the Stack Segment.\n * `DB` (Define Byte): Allocates 8\text{-bit} byte variable storage.\n * Example: `LIST DB 7FH, 42H, 35H`\n * `DW` (Define Word): Allocates 16\text{-bit} word storage across two consecutive byte memory locations per value.\n * Example: `ALIST DW 6512H, 7251H, 4DE2H` (Reserves 6 consecutive byte locations).\n * `SEGMENT` and `ENDS`: Mark the start and end of a program segment block.\n * Syntax:\n ```assembly\n Segname SEGMENT\n ; Program code or instructions\n Segname ENDS\n ```\n * `ASSUME`: Informs assembler which segment register corresponds to a defined logical segment.\n * Example: `ASSUME CS:CODE, DS:DATA`\n * `ORG` (Origin): Sets the initial logical offset location counter for subsequent statements.\n * Example: `ORG 1000H` (Stores subsequent instructions starting at offset 1000_{\text{H}}).\n * `END`: Terminates program assembly. All statements following `END` are ignored.\n * `EVEN`: Directs assembler to align subsequent data or instructions on an even physical memory boundary.\n * `PROC` and `ENDP`: Define boundaries of subroutines/procedures.\n * Used with `NEAR` (intrasegment call) or `FAR` (intersegment call).\n * Syntax:\n ```assembly\n procname PROC NEAR\n ; Procedure statements\n RET\n procname ENDP\n ```\n * `AT`: Instructs assembler to locate a segment at an absolute base segment address.\n * Example: `.data AT 5000H` (Starts data segment at base address 50000_{\text{H}}).\n\n# 8086 Instruction Set Reference\n\n* **Data Transfer Instructions**:\n * `MOV D, S`: Copies source SDD = S). E.g., `MOV AX, CX`, `MOV AL, CH`, `MOV BL, [SI]`.\n * `PUSH S`: Pushes word S\text{SS}:[\text{SP}-1] \leftarrow S_{High}, \text{SS}:[\text{SP}-2] \leftarrow S_{Low}, \text{SP} \leftarrow \text{SP}-2). E.g., `PUSH DX`, `PUSH AX`.\n * `POP D`: Pops word from stack into DD_{Low} \leftarrow \text{SS}:[\text{SP}], D_{High} \leftarrow \text{SS}:[\text{SP}+1], \text{SP} \leftarrow \text{SP}+2). E.g., `POP AX`, `POP DX`.\n * `PUSHF`: Pushes Flag Register onto stack.\n * `POPF`: Pops word from stack into Flag Register.\n * `XCHG D, S`: Exchanges contents of DS. E.g., `XCHG DX, AX`.\n * `IN D, S`: Copies byte or word from I/O port SD[80_{\text{H}}][81_{ ext{H}}][\text{DX}][\text{DX}+1]).\n * `OUT D, S`: Copies byte or word from accumulator SD. E.g., `OUT 80H, AL`, `OUT 80H, AX`, `OUT DX, AX`.\n * `XLAT`: Look-up table translation (\text{AL} \leftarrow \text{DS}:[\text{BX} + \text{AL}]).\n * `LAHF`: Loads lower byte of Flag Register into `AH` register.\n * `SAHF`: Stores `AH` register into lower byte of Flag Register.\n * `LEA D, S`: Loads effective address offset of source into destination register. E.g., `LEA BX, [SI + 66H]`.\n * `LDS D, S`: Loads destination register with lower 2 bytes and `DS` register with upper 2 bytes from memory source point. E.g., `LDS SI, [DI]`.\n * `LES D, S`: Loads destination register with lower 2 bytes and `ES` register with upper 2 bytes from memory source. E.g., `LES BX, [DI]`.\n\n* **Arithmetic Instructions**:\n * `ADD D, S`: Addition (D = D + S). E.g., `ADD DH, CL`.\n * `ADC D, S`: Addition with Carry (D = D + S + \text{CF}). E.g., `ADC AX, BX`.\n * `SUB D, S`: Subtraction (D = D - S). E.g., `SUB AX, BX`.\n * `SBB D, S`: Subtraction with Borrow (D = D - S - \text{CF}). E.g., `SBB DX, BX`.\n * `CMP D, S`: Compares DSD - SDS. E.g., `CMP AL, DL`.\n * `MUL Reg`: Unsigned multiplication. For 8\text{-bit}AX = AL \times \text{Reg8}16\text{-bit}DX:AX = AX \times \text{Reg16}. E.g., `MUL BH`, `MUL CX`.\n * `IMUL Reg`: Signed multiplication. E.g., `IMUL CX`.\n * `DIV Reg`: Unsigned division. For 8\text{-bit}AX / \text{Reg8} \rightarrow AL = \text{Quotient}, AH = \text{Remainder}$. For register: DX:AX / \text{Reg16} \rightarrow AX = \text{Quotient}, DX = \text{Remainder}$. E.g., `DIV BL`, `DIV CX`.\n * `IDIV Reg`: Signed division. E.g., `IDIV BL`.\n * `INC D`: Increment by 1 (D = D + 1). E.g., `INC AX`.\n * `DEC D`: Decrement by 1 (D = D - 1). E.g., `DEC BL`.\n * `CBW`: Convert byte in `AL` to word in `AX` via sign extension.\n * `CWD`: Convert word in `AX` to double-word in `DX:AX` via sign extension.\n * `NEG D`: Replaces DD = 0 - D). E.g., `NEG AL`.\n * `DAA`: Decimal Adjust Accumulator after addition (adjusts `AL` to packed BCD).\n * `DAS`: Decimal Adjust Accumulator after subtraction.\n * `AAA`: ASCII Adjust Accumulator after addition.\n * `AAS`: ASCII Adjust Accumulator after subtraction.\n * `AAM`: ASCII Adjust Accumulator after multiplication.\n * `AAD`: ASCII Adjust Accumulator before division.\n\n* **Logic, Shift, and Rotate Instructions**:\n\n\n\n * `AND D, S`: Bitwise AND (D = D \text{ AND } S). E.g., `AND AX, CX`.\n * `OR D, S`: Bitwise OR (D = D \text{ OR } S). E.g., `OR AX, BX`.\n * `NOT D`: Bitwise NOT / 1's Complement (D = \text{NOT } D). E.g., `NOT AL`.\n * `XOR D, S`: Bitwise Exclusive-OR (D = D \text{ XOR } S). E.g., `XOR AL, BL`.\n * `TEST D, S`: Performs bitwise AND (D \text{ AND } S) to update flags without altering destination operand. E.g., `TEST AX, 8000H`.\n * `SHR D, 1/CL`: Logical right shift (0 \rightarrow \text{MSB} \dots \text{LSB} \rightarrow \text{CF}). E.g., `SHR AL, 01H`.\n * `SHL/SAL D, 1/CL`: Logical/Arithmetic left shift (\text{CF} \leftarrow \text{MSB} \dots \text{LSB} \leftarrow 0). E.g., `SHL AX, CL`, `SAL Byte Ptr[SI], 1`.\n * `SAR D, 1/CL`: Arithmetic right shift (preserves sign MSB: \text{MSB} \rightarrow \text{MSB} \dots \text{LSB} \rightarrow \text{CF}). E.g., `SAR AL, 01H`, `SAR Word Ptr[BX], CL`.\n * `ROR D, 1/CL`: Rotate right (LSB rotates to MSB and enters CF). E.g., `ROR BL, CL`, `ROR AL, 1`.\n * `ROL D, 1/CL`: Rotate left (MSB rotates to LSB and enters CF). E.g., `ROL BX, 01H`, `ROL BX, CL`.\n * `RCR D, 1/CL`: Rotate right through Carry Flag. E.g., `RCR BL, CL`, `RCR Word Ptr[BX], CL`.\n * `RCL D, 1/CL`: Rotate left through Carry Flag. E.g., `RCL BX, 01H`, `RCL Byte Ptr[SI], 1`.\n\n* **String Manipulating Instructions**:\n * `MOVSB / MOVSW`: Move string byte or word from `DS:SI` to `ES:DI`. `SI` and `DI` auto-increment/decrement by 1 (byte) or 2 (word).\n * `LODSB / LODSW`: Load string byte/word from `DS:SI` into `AL` or `AX`. Auto-inc/dec `SI`.\n * `STOSB / STOSW`: Store string byte/word from `AL` or `AX` into `ES:DI`. Auto-inc/dec `DI`.\n * `CMPSB / CMPSW`: Compare string byte/word at `DS:SI` with `ES:DI`. Updates flags.\n * `SCASB / SCASW`: Scan string byte/word at `ES:DI` against `AL`/`AX`. Updates flags.\n * `REP`: Repeat string instruction while CX eq 0. E.g., `REP MOVSB`.\n * `REPE / REPZ`: Repeat string instruction while Zero Flag ZF = 1CX eq 0.\n * `REPNE / REPNZ`: Repeat string instruction while Zero Flag ZF = 0CX eq 0.\n * *Assembly Routine Example 1: Clear 50 bytes in Extra Segment starting at offset 2000H*:\n ```assembly\n MOV DI, 2000H\n MOV CX, 50\n MOV AL, 00H\n CLD\n REP STOSB\n ```\n * *Assembly Routine Example 2: Block transfer 100 bytes from DS:5000H to ES:6000H*:\n ```assembly\n MOV SI, 5000H\n MOV DI, 6000H\n MOV CX, 100\n CLD\n REP MOVSB\n ```\n\n* **Control Transfer / Branch Instructions**:\n * `CALL address`: Calls subroutine, saving return CS:IP on stack. E.g., `CALL Addition`.\n * `RET`: Returns from subroutine to main program.\n * `IRET`: Returns from Interrupt Service Routine to main program.\n * `JMP address`: Unconditional control jump. E.g., `JMP New`.\n * `LOOP address`: Decrements `CX` and jumps to target address if CX eq 0. E.g., `LOOP Next`.\n * `LOOPE / LOOPZ address`: Decrements `CX`, jumps if ZF = 1CX eq 0.\n * `LOOPNE / LOOPNZ address`: Decrements `CX`, jumps if ZF = 0CX eq 0.\n * `JC / JNC`: Jump if Carry (CF = 1CF = 0).\n * `JZ / JNZ` (or `JE / JNE`): Jump if Zero (ZF = 1ZF = 0).\n * `JO / JNO`: Jump if Overflow (OF = 1OF = 0).\n * `JP / JNP` (or `JPE / JPO`): Jump if Parity Even (PF = 1PF = 0).\n * `JS / JNS`: Jump if Sign Negative (SF = 1SF = 0).\n * `JA / JNBE`: Jump if Above (CF = 0\text{ and } ZF = 0).\n * `JNA / JBE`: Jump if Not Above / Below or Equal (CF = 1\text{ or } ZF = 1).\n * `JB / JNAE`: Jump if Below (CF = 1\text{ and } ZF = 0).\n * `JNB / JAE`: Jump if Not Below / Above or Equal (CF = 0\text{ or } ZF = 1).\n * `JG / JNLE`: Jump if Greater (SF = 0\text{ and } ZF = 0).\n * `JNG / JLE`: Jump if Not Greater / Less or Equal (SF = 1\text{ or } ZF = 1).\n * `JL / JNGE`: Jump if Less (SF = 1\text{ and } ZF = 0).\n * `JNL / JGE`: Jump if Not Less / Greater or Equal (SF = 0\text{ or } ZF = 1).\n * `JCXZ address`: Jump if `CX` register equals 0 (CX = 0).\n\n* **Processor Control / Machine Control Instructions**:\n * `STC`: Set Carry Flag (CF \leftarrow 1).\n * `CLC`: Clear Carry Flag (CF \leftarrow 0).\n * `CMC`: Complement Carry Flag (CF \leftarrow \overline{CF}).\n * `STD`: Set Direction Flag (DF \leftarrow 1).\n * `CLD`: Clear Direction Flag (DF \leftarrow 0).\n * `STI`: Set Interrupt Flag (IF \leftarrow 1).\n * `CLI`: Clear Interrupt Flag (IF \leftarrow 0).\n * `NOP`: No Operation.\n * `LOCK`: Instruction prefix activating \overline{ ext{LOCK}} pin to lock system bus.\n * `WAIT`: Suspends execution to check \overline{ ext{TEST}}$$ pin state (monitorsBUSYpin of 8087 coprocessor).
ESC: Escape instruction prefix used to pass instructions to 8087 coprocessor.