Comprehensive Study Guide for 8086 Microprocessor: Architecture, Programming, and Instruction Set
8086 Hardware Architecture and Pin Functions
Functional Units of the 8086 Architecture:
The 8086 microprocessor architecture is internally divided into two independent functional units: the Bus Interface Unit (BIU) and the Execution Unit (EU).
Bus Interface Unit (BIU):
Handles all data and address transfers on the buses for the Execution Unit.
Contains the 16-bit Segment Registers: Extra Segment (), Code Segment (), Stack Segment (), and Data Segment ().
Contains the 16-bit Instruction Pointer ().
Houses a dedicated 20-bit Address Generation Adder () that calculates the 20-bit physical address by shifting the segment address left by 4 bits and adding the 16-bit offset.
Features a 6-byte Instruction Stream Byte Queue configured as a First-In, First-Out (FIFO) buffer to prefetch and hold instructions.
Interfaces directly with external memory and peripheral I/O devices via the system bus.
Execution Unit (EU):
Responsible for decoding and executing fetched instructions.
Contains the 16-bit Arithmetic Logic Unit (ALU) for arithmetic and logical computations.
Contains the 16-bit Flag Register (status and control flags) and temporary operand registers.
Houses eight general-purpose registers: (), (), (), and ().
Houses pointer and index registers: Stack Pointer (), Base Pointer (), Source Index (), and Destination Index ().
Includes an internal control system that decodes instructions received from the queue and coordinates internal operations.

Pipelining Mechanism in 8086:
Pipelining is the technique of overlapping instruction fetch, decode, and execution mechanism.
To speed up program execution, the BIU fetches as many as 6 instruction bytes ahead of time from memory into an internal 6-byte prefetch queue.
The instruction prefetching queue operates as a 6-level deep FIFO buffer.
While the EU is decoding or executing an instruction that does not require use of the external buses, the BIU simultaneously fetches subsequent instruction bytes from memory.
When the EU is ready for its next instruction, it reads the instruction directly from the prefetch queue in the BIU rather than waiting for an external bus cycle.
Eliminates the waiting time that would otherwise occur if the execution unit had to send out an address to memory and wait for each instruction byte to be returned.
Greatly improves processor throughput and overall processing speed.

Pin Functions:
READY Pin:
Input pin used as an acknowledgement signal from slower memory or peripheral I/O devices.
Active-high signal.
When driven high, it indicates to the microprocessor that the addressed device is ready to transfer data.
If logic low during a bus cycle, the 8086 inserts wait states () until the signal goes high.
INTR (Interrupt Request) Pin:
Level-triggered interrupt request input.
Sampled by the processor during the last clock cycle of each instruction.
Determines whether an external hardware interrupt request is pending.
If is active and the Interrupt Flag () is set, the processor enters an interrupt acknowledge cycle to process the interrupt.
Register Organization and Flag Register
Structure of the Flag Register:
The 8086 features a 16-bit register designated as the Flag Register (or Program Status Word).
Contains nine active 1-bit flags divided into two categories: six Status/Conditional Flags and three Control Flags.
The remaining seven bits (, , , and through ) are undefined (marked as ).

Bit Mapping of the Flag Register:
Bit 0 (): Carry Flag
Bit 1 (): Undefined
Bit 2 (): Parity Flag
Bit 3 (): Undefined
Bit 4 (): Auxiliary Carry Flag
Bit 5 (): Undefined
Bit 6 (): Zero Flag
Bit 7 (): Sign Flag
Bit 8 (): Trap Flag
Bit 9 (): Interrupt Enable Flag
Bit 10 (): Direction Flag
Bit 11 (): Overflow Flag
Bits 12–15 (): Undefined
Status / Conditional Flags:
Carry Flag (): Set to 1 when a carry or borrow is generated out of the Most Significant Bit (MSB) of the result ( for an 8-bit operation, for a 16-bit operation); otherwise, it is cleared to 0.
Parity Flag (): Set to 1 if the lower 8 bits (least significant byte) of the operation result contain an even number of 1s (even parity); otherwise, it is reset to 0 (odd parity).
Auxiliary Carry Flag (): Set to 1 if a carry or borrow is generated from the lower nibble to the higher nibble (from bit to bit ); otherwise, it is reset.
Zero Flag (): Set to 1 if the result of an arithmetic or logical operation is zero; otherwise, it is reset to 0.
Sign Flag (): Set equal to the MSB of the result ( for 8-bit, for 16-bit). If the MSB is 1, indicating a negative signed number, ; if 0, indicating a positive result, .
Overflow Flag (): Set to 1 if an arithmetic overflow occurs in signed operations, meaning the signed result is too large in magnitude to fit into the destination register; otherwise, cleared to 0.
Control Flags:
Trap Flag (): When set to 1, puts the processor into single-step execution mode for debugging, generating an internal interrupt after each instruction.
Interrupt Enable Flag (): Used to mask (disable) or unmask (enable) the maskable hardware interrupt . When set to 1, the 8086 recognizes external interrupts on ; when cleared to 0, requests are ignored.
Direction Flag (): Determines the direction of address modification for string operations involving index registers and . Setting decrements the pointers (auto-decrement mode), while clearing increments the pointers (auto-increment mode).
Memory Addressing, Segmentation, and Physical Address Calculation
Definitions of Address Types:
Logical Address: The address at which an instruction or data item appears to reside from the perspective of an executing application program. Specified as a segment:offset pair () and translated into a physical address by the BIU.
Effective Address () / Offset Address: An unsigned 16-bit displacement value representing the distance in bytes from the base address of a segment to the targeted operand or memory location. Handled by pointer and index registers (, , , , or immediate values).
Physical Address Generation Process:
The 8086 features a 20-bit external address bus enabling access to () of physical memory.
Physical address formation proceeds through the following sequential steps:
Segment registers hold a 16-bit base address.
The BIU internally shifts the 16-bit base address 4 bit positions to the left (equivalent to multiplying the value by or appending four zero bits: to the LSB). This expands the value into a 20-bit base address.
The offset address is stored as a 16-bit value in a pointer, base, or index register.
The 16-bit offset address is added to the 20-bit shifted base address inside the internal address adder (), producing the final 20-bit physical address.
Physical Address Formula:

Worked Example:
Given Segment Register () =
Given Index Register () =
Step 1: Shift left by 4 bits ():
Step 2: Add the effective address () to the base address:
Step 3: Perform hexadecimal addition:
The resulting physical address is .
Instruction Formats and Addressing Modes
Machine Language Instruction Format for Register-to-Register Transfer:
Instructions transferring data between registers consist of a two-byte encoding format.
Byte 1:
Bits – (): Operational Code () specifying the operation.
Bit (): Direction bit. Specifies destination or source:
: The register specified in the field is the destination operand.
: The register specified in the field is the source operand.
Bit (): Word/Byte operation indicator:
: Byte operation (8 bits).
: Word operation (16 bits).
Byte 2:
Bits – (): Mode field. Set to
11to specify a pure register-to-register operation (no memory operand/displacement).Bits – (): 3-bit code selecting the general register operand.
Bits – (): 3-bit register/memory specifier. With , this field selects the second register operand.

Addressing Modes of the 8086:
Immediate Addressing Mode:
The 8-bit or 16-bit operand (constant data) is directly included within the instruction itself.
Example:
MOV AX, 67D3H(loads the 16-bit immediate value into register ).Register Addressing Mode:
The operand is contained within one of the internal general-purpose or segment registers.
Example:
MOV AX, CX(copies the 16-bit content of register into register ).Direct Addressing Mode:
The 16-bit effective address (offset) of the memory operand is explicitly supplied within the instruction.
Example:
MOV CL, [2000H](loads the byte located at offset address in the data segment into register ).Register Indirect Addressing Mode:
The effective address of the memory operand is held in a base register () or pointer/index register (, , ).
Example:
MOV AX, [BX](loads with the 16-bit word from the memory address specified by in the default data segment).Indexed Addressing Mode:
The offset address of the operand is stored in an index register ( or ).
is the default segment for and ; for string operations, and serve as default segments for and respectively.
Considered a specialized form of register indirect addressing.
Example:
MOV AX, [SI](retrieves the 16-bit word from the offset pointed to by ).Based Indexed Addressing Mode:
The effective address is computed by summing the contents of a base register ( or ) and an index register ( or ).
The default segment is when using , or when using .
Example:
MOV AX, [BX][SI](effective address equals ).Register Relative Addressing Mode:
The operand's offset is formed by adding an 8-bit or 16-bit displacement value to the contents of a base or index register (, , , or ).
Example:
MOV AX, 50H[BX](effective address equals ).Relative Based Indexed Addressing Mode:
The effective address is calculated by summing an 8-bit or 16-bit displacement with the contents of both a base register and an index register.
Example:
MOV AX, 50H[BX][SI](effective address equals ).
Instruction Set and Operation Details
Data Transfer Instructions:
XCHG (Exchange):
Exchanges the contents of a destination register with the contents of a source register or memory location.
Cannot directly exchange contents of two memory locations.
Syntax:
XCHG destination, sourceExample:
XCHG AX, BX(exchanges the 16-bit contents of register with ).
Flag Manipulation Instructions:
STC (Set Carry Flag):
Sets the Carry Flag to logic 1.
Operation: CF \thickleftarrow 1
CMC (Complement Carry Flag):
Inverts the current state of the Carry Flag.
Operation: CF \thickleftarrow \thicksim CF
Logical Instructions:
AND (Logical AND):
Performs a bitwise logical AND operation between each bit of the source and destination operands and stores the result in the destination.
Syntax:
AND destination, sourceOperation: \text{Destination} \thickleftarrow \text{destination AND source}
Flags Affected: , , and updates , , .
Bitwise Example:
AND AL, BLInitial values:
Computation:
Final result: AL \thickleftarrow 0000\text{ }0000_2
OR (Logical Inclusive OR):
Performs a bitwise logical OR operation between corresponding bits of the source and destination, placing the result in the destination.
Syntax:
OR destination, sourceOperation: \text{Destination} \thickleftarrow \text{destination OR source}
Flags Affected: , , and updates , , .
Bitwise Example:
OR AL, BLInitial values:
Computation:
Final result: AL \thickleftarrow 1111\text{ }1111_2
NOT (Logical Invert):
Inverts every individual bit (one's complement) of the specified destination operand.
Syntax:
NOT destinationOperation: \text{Destination} \thickleftarrow \text{NOT destination}
Flags Affected: None (status flags remain unchanged).
Bitwise Example:
NOT BLInitial value:
Final result:
XOR (Logical Exclusive-OR):
Performs a bitwise exclusive-OR between matching bits of source and destination, placing the outcome in the destination.
Syntax:
XOR destination, sourceOperation: \text{Destination} \thickleftarrow \text{destination XOR source}
Flags Affected: , , and updates , , .
Bitwise Example:
XOR AL, BLInitial values:
Computation:
Final result: AL \thickleftarrow 1111\text{ }1111_2
TEST (Logical Compare):
Performs a bitwise AND between the source and destination operands and updates flags accordingly, without modifying either operand.
Syntax:
TEST Destination, SourceOperation: \text{Flags} \thickleftarrow \text{evaluated from (destination AND source)}
Flags Affected: Updates , , ; clears and .
Examples:
TEST AL, BL: Performs bitwise AND of with ; discards numerical result; updates , , .Given
MOV AL, 00000101b:TEST AL, 1testing bit 0 () yields .TEST AL, 10btesting bit 1 () yields .
String Manipulation Instructions and Repeat Prefixes:
Repeat Prefixes:
REP: Prefix written before a string instruction. Causes the instruction to repeat while decrementing count register until .
REPE / REPZ (Repeat while Equal / Zero): Repeats the string instruction as long as compared bytes or words match () and .
REPNE / REPNZ (Repeat while Not Equal / Not Zero): Repeats the instruction as long as compared elements are not equal () and .
Syntax Example:
REP MOVSB
MOVS / MOVSB / MOVSW (Move String Byte or Word):
Transmits a byte or word from a location in the Data Segment pointed to by to a location in the Extra Segment pointed to by .
Syntax:
MOVS destination, sourceorMOVSBorMOVSWOperation: ES:[DI] \thickleftarrow DS:[SI]
Modifies and by incrementing (if ) or decrementing (if ) by 1 (for byte) or 2 (for word).
Example Usage:
assembly LEA SI, Source LEA DI, destination CLD MOV CX, 04H REP MOVSB
CMPS / CMPSB / CMPSW (Compare String Byte or Word):
Compares a byte or word addressed by with an element addressed by by subtraction, modifying flags without altering either memory operand.
Syntax:
CMPS destination, sourceorCMPSBorCMPSWOperation: \text{Flags affected} \thickleftarrow DS:[SI] - ES:[DI]
Auto-increments or auto-decrements and according to the status of .
Example Usage:
assembly LEA SI, Source LEA DI, destination CLD MOV CX, 100 REPE CMPSB
SCAS / SCASB / SCASW (Scan String Byte or Word):
Compares the content of accumulator register (byte) or (word) with a memory byte/word addressed by .
Syntax:
SCAS destinationorSCASBorSCASWOperation: \text{Flags affected} \thickleftarrow AL/AX - ES:[DI]
Operates on strings residing in the Extra Segment (). Sets when a match is detected.
Example Usage:
assembly LEA DI, destination MOV AL, 0DH MOV CX, 80H CLD REPNE SCASB
LODS / LODSB / LODSW (Load String Byte or Word):
Copies a byte or word from the data segment pointed to by into accumulator or .
Syntax:
LODS sourceorLODSBorLODSWOperation: AL/AX \thickleftarrow DS:[SI]
Updates pointer based on .
Example Usage:
assembly LEA SI, Source CLD LODSB STOS / STOSB / STOSW (Store String Byte or Word):
Copies a byte from or word from into a memory location pointed to by in the Extra Segment.
Syntax:
STOS destinationorSTOSBorSTOSWOperation: ES:[DI] \thickleftarrow AL/AX
Updates pointer based on .
Assembly Instructions for Specific Tasks:
Rotate register BL right 4 times:
assembly MOV CL, 04H ROR BL, CL (Alternative rotate forms include usingROL,RCR, orRCLwith count registerCL).
Multiply AL by 04H:
assembly MOV BL, 04H MUL BL Signed division of AX by BL:
assembly IDIV BL Move 2000H into BX register:
assembly MOV BX, 2000H Increment the counter of AX by 1:
assembly INC AX Compare AX with BX:
assembly CMP AX, BX
Assembly Language Programming Fundamentals and Tools
Assembly Language Programming Tools:
Editors: Programs used to create, write, and modify the source code text file of an assembly language program (typically saved with an
.ASMextension).Assembler: Translates symbolic assembly language mnemonic statements into binary machine code object files (
.OBJ). Examples include MASM and TASM.Linker: Combines independently assembled object modules, resolves external references, assigns absolute or relative addresses, and produces an executable binary program (
.EXE).Debugger: Software tool allowing developers to execute a program step-by-step, inspect and edit register contents, monitor memory locations, and insert breakpoints to identify and resolve logic errors.
Program Development Steps:
Defining the problem: Carefully identify the operations the software must execute, understand the input requirements, expected outputs, constraints, and operational environment.
Algorithm: Formulate a step-by-step sequential specification of computational and logical actions expressed in plain, clear language.
Flowchart: Create a graphical diagram using standardized flow symbols representing the sequence, decision branches, loops, and overall control structure.
Initialization checklist: Compile a list of all data items, constants, memory variables, hardware ports, registers, and operational flags requiring initialization prior to execution.
Choosing instructions: Select optimal processor instructions that produce compact object code and maximize execution speed.
Converting algorithms to assembly language program: Systematically transcribe each algorithmic step into corresponding assembly language statements and directives.
Assembler Directives:
DW (Define Word):
Informs the assembler to allocate 16-bit word storage locations in memory and optionally assign initial data values.
Example:
MULTIPLIER DW 437AHreserves one word namedMULTIPLIERand initializes it to .EQU (Equate):
Assigns a symbolic label or constant name to a specific numerical expression or string. During assembly, the assembler replaces all occurrences of the symbol with its defined value.
Example:
assembly DATA SEGMENT Num1 EQU 50H Num2 EQU 66H DATA ENDS Assigns the numeric values and to constantsNum1andNum2.ASSUME:
Instructs the assembler on which segment register (, , , ) is associated with which logical segment label defined in the program.
Informs the assembler that segment register corresponds to code block label
CODE, and corresponds to data block labelDATA.OFFSET:
An operator that calculates the 16-bit displacement (offset address) of a variable, data item, or procedure from the beginning of its enclosing segment.
Example:
MOV BX, OFFSET PRICESloads the offset distance of the memory itemPRICESinto register .SEGMENT and ENDS:
Directives used to bracket and delineate the boundaries of a logical program segment containing data, code, or stack definitions.
Example:
CODE SEGMENTstarts a logical section namedCODE, which is closed byCODE ENDS.EVEN (Align on Even Memory Address):
Instructs the assembler to update its internal Location Counter () to the next even memory boundary address if it is currently pointing to an odd address.
Inserts a dummy
NOP() byte to maintain alignment, allowing faster 16-bit bus transfers from word-aligned addresses.
Macros:
Definition: A named block of instructions containing frequently repeated sequences of code that perform the same computational task across varying data items. The sequence is defined once and expanded in-line at each location where the macro is called.
General Syntax:
assembly Macro_name MACRO [arg1, arg2, ..... argN] ; Sequence of instructions ENDM
Procedure Calls and Flow Control Mechanisms
Intersegment vs. Intrasegment Procedures:
Parameter / Feature | Intersegment Call (Far Call) | Intrasegment Call (Near Call) |
|---|---|---|
Alternative Terminology | Far procedure call | Near procedure call |
Segment Location | Target procedure resides in a different code segment than the calling instruction. | Target procedure resides in the same code segment as the calling instruction. |
Register Modifications | Replaces both Code Segment and Instruction Pointer () pair. | Replaces only the Instruction Pointer (). Code segment () is unchanged. |
Stack Operations | Pushes both old and old onto the stack: | Pushes only the old onto the stack: |
Stack Overhead | Requires more stack memory ( total). | Requires less stack memory ( total). |
Assembly Syntax Example |
|
|
Re-entrant Procedures:
A software design scenario where Procedure 1 is invoked from the main program, Procedure 1 subsequently calls Procedure 2, and Procedure 2 invokes Procedure 1 again before the first invocation completes.
Under this condition, execution flow re-enters Procedure 1.
Execution returns properly via the stack:
The
RETinstruction at the end of the second invocation of Procedure 1 returns execution back to Procedure 2.The
RETstatement terminating Procedure 2 returns control back to the first instance of Procedure 1 at the instruction following its call to Procedure 2.The final
RETin Procedure 1 returns control back to the main program instruction immediately following the original procedure call.

Recursive Procedures:
A specialized procedure that directly or indirectly calls itself.
Commonly employed when processing complex, recursive data structures such as hierarchical trees.
In a procedure invoked with a recursion depth parameter , each iterative invocation decrements by one until the base condition is satisfied, after which nested
RETinstructions execute in reverse sequence to unwind back to the mainline caller.

Assembly Language Programs and Flowcharts
Multiplication of Two 16-bit Numbers:
Multiplication of two 16-bit unsigned numbers results in a product up to 32 bits wide, partitioned across two 16-bit registers: the most significant word in and the least significant word in .

16-bit Number Addition Program:
Program Listing: ```assembly DATA SEGMENT NUMBER1 DW 6753H NUMBER2 DW 5856H SUM DW 0 DATA ENDS
CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV AX, NUMBER1 MOV BX, NUMBER2 ADD AX, BX MOV SUM, AX MOV AH, 4CH INT 21H CODE ENDS END START ```
String Length Calculation Program:
Calculates the number of characters in a string terminated by a special character (
' LEN DB ? DATA ENDS
CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV DX, DATA MOV DS, DX LEA SI, STRG MOV CL, 00H MOV AL, '$' NEXT: CMP AL, [SI] JZ EXIT ADD CL, 01H INC SI JMP NEXT EXIT: MOV LEN, CL MOV AH, 4CH INT 21H CODE ENDS END START ```
Evaluation of Using a Macro:
Computes the sum of squares of two 8-bit unsigned integers and using an inline parametric macro expansion.
Program Listing: ```assembly .MODEL SMALL
PROG MACRO a, b MOV AL, a MUL AL MOV BL, AL MOV AL, b MUL AL ADD AL, BL ENDM
.DATA x DB 02H y DB 03H p DB DUP()
.CODE START: MOV AX, DATA MOV DS, AX PROG x, y MOV p, AL MOV AH, 4CH INT 21H END START ```
Count the Number of Zeros in a 16-Bit Word:
Inspects each bit of a 16-bit variable by rotating it into the carry flag and incrementing a counter whenever a zero is found.
Program Listing: ```assembly DATA SEGMENT N DB 1237H Z DB 0 DATA ENDS
CODE SEGMENT ASSUME DS: DATA, CS: CODE START: MOV DX, DATA MOV DS, DX MOV AX, N MOV CL, 08 NEXT: ROL AX, 01 JC ONE INC Z ONE: LOOP NEXT HLT CODE ENDS END START ```
Find the Largest Number in an Array:
Finds the largest value among five array elements: , , , , and .
Program Listing: ```assembly DATA SEGMENT ARRAY DB 10H, 24H, 02H, 05H, 17H LARGEST DB 00H DATA ENDS
CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV DX, DATA MOV DS, DX MOV CX, 04H MOV SI, OFFSET ARRAY MOV AL, [SI] UP: INC SI CMP AL, [SI] JNC NEXT MOV AL, [SI] NEXT: DEC CX JNZ UP MOV LARGEST, AL MOV AX, 4C00H INT 21H CODE ENDS END START ```
Addition of an 8-bit Series Using a Procedure:
Adds a series of five 8-bit values (, , , , ) using a separate subroutine to perform the accumulation and track carry.
Program Listing: ```assembly DATA SEGMENT NUM1 DB 10H, 20H, 30H, 40H, 50H RESULT DB 0H CARRY DB 0H DATA ENDS
CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV DX, DATA MOV DS, DX MOV CL, 05H MOV SI, OFFSET NUM1 UP: CALL SUM INC SI LOOP UP MOV AH, 4CH INT 21H
SUM PROC ; Procedure to add an 8-bit number MOV AL, [SI] ADD RESULT, AL JNC NEXT INC CARRY NEXT: RET SUM ENDP
CODE ENDS END START ```
String Reversal Program and Flowchart:
Program Listing: ```assembly DATA SEGMENT STRB DB 'GOOD MORNING$' REV DB 0FH DUP(?) DATA ENDS
CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV DX, DATA MOV DS, DX LEA SI, STRB MOV CL, 0FH LEA DI, REV ADD DI, 0FH UP: MOV AL, [SI] MOV [DI], AL INC SI DEC DI LOOP UP MOV AH, 4CH INT 21H CODE ENDS END START ```
