Sunday, 9 February 2025

Instruction Set of 8086 Microprocessor

 Unit 3

Instruction Set of 8086 Microprocessor

The instruction set of the 8086 microprocessor consists of a variety of instructions that enable the processor to perform different operations. These instructions are classified into different groups based on their functionality.

 It has ability to work with older system and offering wide variety of instructions, making it useful for programmers. As technology changes, the concepts introduced by 8086 mains constant, showing its significance in the world of computing.

Machine Language Instruction Format

The 8086 instruction set is a group of commands that the Intel 8086 microprocessor uses to perform tasks. It includes a variety of instructions that allow developers to create software for many different tasks, from simple math to more complex processing. Understanding this instruction set is essential for anyone looking to work with the 8086 microprocessor and its applications.

There are one or more fields in machine language instruction format.

The first field is called operation code (or opcode) field.It indicates the operation to be performed by microprocessor. There are other fields known as operand fields.

The microprocessor performs different operations on these fields. The length of an instruction is determined by opcode & operand fields. The length an instruction may vary from one byte to six bytes.


The 8086 instruction set consists of instructions with different formats depending on the operation, operands, and addressing modes. The instruction formats define how opcode, operands, addressing modes, and other fields are arranged in the instruction.

There are six general formats of 8086 instructions:

  1. One-byte Instruction Format
  2. Register to Register Format
  3. Register to/from Memory with MOD-REG-R/M Format
  4. Immediate Operand to Register Format
  5. Immediate Operand to Memory Format
  6. Direct Addressing Format

There are six general formats of instructions in 8086 instruction set. These are described below.

1. One-Byte Instruction Format

  • This format is one byte (8 bits) long.
  • It may have the implied data or register operands. 
  • Three least significant bits (LSB) of opcode are used to specify the register operand if any, otherwise, all 8 bits form an opcode and operands are implied.
  • It is used for register and flag operations or single-byte opcode instructions.
  • No additional operands are required.
Example: 
CLC ; Clear carry flag (OpCode fits in 1 byte) 
STC ; Set carry flag

2. Register to Register:

  • This format is two byte long. 
  • The first byte of instruction gives the opcode and size of operand (16 bit/8 bit) with help of w bit.
  • The second byte of instruction gives the register operands and R/M fields.
  • Used for register-to-register operations (both operands are registers).
  • The MOD-REG-R/M format is used.
  • Example :

    MOV AX, BX  ; Moves contents of BX into AX

    ADD DX, CX  ; Adds CX to DX

    3. Register to Memory/Memory to Register without displacement:

  • This format is two byte long and similar to ‘register to register’ format. 
  • Here MOD field is 00.

  • Example :

    MOV AX, BX  ; Moves contents of BX into AX

    ADD DX, CX  ; Adds CX to DX

    4. Register to Memory/Memory to Register with displacement:

  • Used for register and memory operand transfers.
  • Uses the MOD-REG-R/M format.
  • This instruction format contains one byte (for 8 bit displacement) or two bytes (for 16 bit displacement) additional along with the previous format.

  • Fields Explained:

    • MOD specifies memory or register mode.
    • R/M gives the register or memory operand.
    • REG holds the register operand.
    Example : 
    MOV AX, [5000H]  ; Load AX from memory location 5000H
    MOV [6000H], BX  ; Store BX at memory location 6000H

    5. Immediate operand to Register:

  • Used when an immediate (constant) value is moved into a register.
  • Opcode specifies operation type and register, followed by the immediate value.
  • In this instruction format, first byte and 3 bits from second byte (D3, D4, D5) are used as opcode. 
  • It contains 2 bytes of immediate operand in case of 16 bit data.
  • Example :

    MOV AX, 1234H  ; Moves immediate value 1234H into AX

    ADD BL, 05H    ; Adds 05H to BL

    6. Immediate operand to Memory with 16 bit displacement:

  • Used when an explicit memory address is given in the instruction.
  • The instruction contains opcode + memory address.
  • This instruction format requires 5 or 6 bytes. 
  • First two bytes contain opcode, MOD and R/M fields. 
  • Next two bytes contain 16 bit displacement and remaining two bytes contain immediate data.

  • Example :

    MOV AL, [1234H]  ; Loads AL from memory location 1234H

    MOV [5678H], CX  ; Stores CX at memory location 5678H

    The opcode has indicator bits as follows:

    1) w bit: In opcode, this bit indicates the size of operand. If w = 0, the operand is 0f 8 bits. If w = 1, the operand is of 16 bits.

    2) d bit: If there are two operands in an instruction, this bit indicates that one operand is in a register. If d = 0, the REG field specifies that it is a source operand. If d = 1, the REG field of opcode specifies that it is a destination operand.

    3) s bit: This bit is called as sign extension bit. This bit along with w bit gives the type of operation.

        i) s = 0, w = 0 : 8 bit operation with 8 bit immediate operand

        ii) s = 0, w = 1 : 16 bit operation with 16 bit immediate operand

        iii) s = 1, w = 1 : 16 bit operation with signed 16 bit immediate operand.

    4) v bit: This bit is used in shift and rotate instructions

        If v = 0, shift count is 1.

        If v = 1, shift count is in CL register.

    5) z bit: this bit is used by REP prefix to control the loop.

    Summary Table of 8086 Instruction Formats

    Format TypeOperands UsedExample
    One-Byte InstructionNo operandsCLC (Clear Carry)
    Register to RegisterTwo registersMOV AX, BX
    Register to/from MemoryRegister and MemoryMOV AX, [5000H]
    Immediate to RegisterRegister and ImmediateMOV AX, 1234H
    Immediate to MemoryMemory and ImmediateMOV [5000H], 20H
    Direct AddressingMemory address given directlyMOV AL, [1234H]

    Addressing Modes

    The addressing modes of computer architecture are the various ways in which operand(s) of an instruction are specified. These modes define how the processor finds the data it needs to execute a command. The Intel 8086 microprocessor has support for many addressing modes, each granting flexibility in addressing memory and registers at the same time.

    Below are the main addressing modes supported by the 8086

    Immediate Addressing

    • In case of immediate addressing, the operand is a constant value or immediate data that is part of the instruction itself.
    • Example: MOV AX, 1234h - copies value 1234h into AX.

    Register Addressing

    • In register addressing, the operand is placed in one of the CPU registers.
    • Example: MOV AX, BX - moves the contents of register BX into register AX.

    Direct Addressing

    • In direct addressing, the operand's address is directly specified in the instruction itself.
    • Example: MOV AX, [1034h] - displaces register AX with the data stored at the memory location 1034h.

    Indirect Addressing

    • In indirect addressing, the address of the operand is stored in a register or memory location, and the data is at that address.
    • Example: MOV AX, [BX] - copies the data pointed to by a 16-bit signed offset relative to a 16-bit register with data type of pointer into a 16-bit register with data type of integer.

    Indexed Addressing

    • In indexed addressing, the operand's address is obtained by computing the offset together with a base address stored in a register.
    • Example: MOV AX, [BX+SI] - Moves the data located at the address formed by adding the contents of BX and SI registers into register AX.

    Based Addressing

    • Like indexed addressing, but the base address is added to the offset in the instruction.
    • Example: MOV AX, [1034h+SI] – loads register AX with data from the address that is 1234h added with SI.

    Based Indexed Addressing

    • Combines based and listed addressing modes, in which an offset is introduced to a base deal with stored in a sign in, and an index sign in is used to in addition regulate the address.
    • Example: MOV AX, [BX DI 10h] - movements the facts positioned on the cope with shaped through adding the contents of BX, DI, and an instantaneous offset of 10h into sign up AX.

    The instructions of 8086 microprocessor are categorized into following main types:

    1) Data copy/transfer instructions:

    These instructions are used to transfer data from source to destination. All move, load, store, input and output instructions belong to this category.

    2) Arithmetic and logical instructions:

    Instructions of this type are used to perform arithmetic, logical, increment, decrement, compare etc. operations.

    3) Branch instructions:

    These instructions transfer execution control to specified address. Cal, jump, return and interrupt instructions belong to this category.

    4) Loop instructions:

    These instructions are used to implement conditional or unconditional loops. The loop count is stored in CX register e.g. LOOP, LOOPZ, LOOPNZ instructions.

    5) Machine control instructions:

    These instructions are used to control 8086 microprocessor itself e.g. NOP, HLT, WAIT and LOCK instructions.

    6) Flag manipulation instructions:

    These instructions are used to set or reset flags of 8086 e.g. STC, CLC, CMC, STI, CLI, CLD, STD instructions.

    7) Shift and Rotate instructions:

    These instructions are used to shift or rotate the bits of operand in either right or left direction. CL register can be used to store the count of shift/rotate operation.

    8) String instructions:

    These instructions are used to perform string manipulation operations such as load, move, store, scan, compare etc.

    Instruction Set

    Data Movement Instructions

    Instructions

    Description

    MOV

    Transfer data from source to destination.

    PUSH

    Push data onto the stack.

    POP

    Pop the data from the stack.

    IN

    Input from a port to accumulator

    OUT

    Output from accumulator to a port

    LDS

    Load pointer using DS register

    LES

    Load pointer using ES register

    LEA

    Load Effective Address (loads the address of a memory operand into a register).

    XCHG

    Swap the contents of two registers or a register and a memory location.

    More Details On Data Movement Instructions

    Arithmetic Instructions

    Instructions

    Description

    ADD

    Adds two operands

    SUB

    Subtracts second operand from first

    ADC

    Add with carry

    SBB

    Subtract with borrow

    MUL

    Unsigned multiplication

    IMUL

    Signed multiplication

    DIV

    Unsigned division

    IDIV

    Signed division

    NEG

    Two’s complement of operand

    INC

    Increments operand by 1

    DEC

    Decrement . operand by 1

    CMP

    Compare two operands

     

    Logic Instructions

    Instructions

    Description

    AND

    Bitwise Performs bitwise AND

    OR

    Bitwise Performs bitwise OR

    XOR

    Bitwise Performs bitwise XOR

    NOT

    Complement each bit of operand

    TEST

    Bitwise AND operation modifies flags while operands remain unchanged.

    SHL

    Shift left (logical)

    SHR

    Shift right (logical)

    SAL

    Shift arithmetic left

    SAR

    Shift arithmetic right

    ROL

    Left rotate, right rotate (with carry).

    ROR

    Rotate Right

    RCL

    Rotate Left

    RCR

    Rotate through carrty right

    RCL

    Rotate through carry left

     

    Control Transfer Instructions

    Instructions

    Description

    JMP

    Absolute jump to a specified address.

    JC

    Jump if carry - Conditional branching on the flags.

    JNC

    Jump If no Carry

    JZ

    Jump if zero or equal i.e. when ZF = 1

    JNZ

    Jump if Not zero or equal i.e. when ZF = 1

    JS

    Jump if sign bit is set

    JNS

    Jump if Sign bit is not set

    JO

    Jump if overflow

    JNO

    Jump if no overflow

    CAL

    Call a subroutine.

    RET

    Return from subroutine.

    INT

    Software interrupt.

    IRET

    Return from Interrupt .

     

    String Instructions

    Instructions

    Description

    MOVSB

    Transfer byte or word from source to destination (used in string manipulation).

    MOVS

    Move String

    LODS

    Load String

    MOVSW

    Move byte or word from memory into the accumulator.

    CMPS

    Compare a string

    CMPSB

    Compare byte or word string operands.

    CMPSW

    Compare string write

    SCASB

    Scan byte or word string operands.

    SCASW

    Compares the content of accumulator with the content of memory location addressed by DI register in the extra segment ES.

    LODSB

    Get a byte or word from memory into the accumulator.

    LODSW

    Loads 8-bit or 16-bit data from memory location addressed by SI register into AL or AX register.

    REP

    Repeat following string instruction

    REPE / REPZ

    Repeat while equal/zero

    REPNE / REPNZ

    Repeat while not equal/non-zero

     

    Input/Output Instructions

    Instructions

    Description

    IN

    Input from port.

    OUT

    Output to port.

     

    Flag Control Instructions

    Instructions

    Description

    CLC

    Clear carry flag

    STC

    Set carry flag

    CMC

    Complement carry flag

    CLD

    Clear direction flag.

    STD

    Set direction flag.

    CLI

    Clear interrupt flag.

    STI

    Set interrupt flag

    HLT

    Halt processor execution.

     

    Other Instructions

    Instructions

    Description

    NOP

    No operation

    HLT

    Halt the processor

    WAIT

    Await external event. Wait for signal

    ESC

    Jump to external coprocessor., Escape to external device

    Lock

    Bus Lock Prefeix


    Process Control Instructions

    • Process Control Instructions are used to control the order execution in a program and in processes. They comprise of instruction for branching, looping, and calling functions or subroutines.
    • In other words, the instruction set changes the sequence of instruction executing, therefore, it allows to change the program flow. Include commands for conditional jump, unconditional jump, subroutine calls among others.

    Instruction

    Description

    Branching Instructions

    Branching Instruction that transfers the flow of execution onto certain conditions or unconditional transfers to the part of the program.

    Looping Instructions

    Instruction that can be used to repeatedly execute a block of code either conditionally or unconditionally.

    Subroutine Instructions

    Subroutine Instructions are used to call and return from subroutine to enhance code modularity and reusability.

    Unconditional Jumps

    Unconditional Jumps Included in the program flow are the instructions that unconditionally jump to a predetermined location without taking any condition in to account.

    Conditional Jumps

    Conditional Jumps Conditionals that moves the control flow to a specific address depending on the truth value of a condition.

    Subroutine Calls

    Jump Commands Instructions that are responsible for transferring control to a subroutine, enabling task execution, while promoting code modularity and reusability.

     

    Challenges

    • Limited Addressing Range: One of the major issues with the 8086 instruction set is its limited addressing range. It can only access directly 1 MB of memory, which can be a problem for modern computing tasks requiring more RAM.
    • Complexity of Memory Management: Managing memory in 8086 architecture, specifically in real mode, can be confusing and tedious. Developers should handle segment registers and offsets to access memory, which may cause mistakes and ineffectiveness.
    • Lack of High-Level Abstractions: The instruction set of the 8086 lacks lots of the high-level abstractions commonly found in modern architectures. This absence also makes special tasks, like complex arithmetic operations or data manipulation, difficult and not so efficient.
    • Limited Instruction Set Extensions: The x86 instruction set of the 8086 processor does not have many advanced instructions and extensions as later x86 processors. Such restrictions can become an obstacle in the optimization of the performance and can make some tasks complicated to implement effectively.
    • Interrupt Handling Complexity: It can be very complex to manage interrupts in 8086 architecture speeds in real mode. Developers have to take care of interrupt vectors, interrupts priority and context switching manually, which makes the code more complex and potentially has errors.

    Advantages of 8086 Instruction Set

    • Compatible with Older System: The 8086-instruction set has the ability to work with other older microprocessors like 8080 and 8085. This ability allows for relocating of software to newer version from older version based on 8086 architectures.
    • Accessibility to different Commands: The 8086 includes variant of commands for different works such as controlling the program, moving data, calculations, helping programmers to create more effective and faster programs.
    • Flexible Memory Access: The 8086 allows developers to access memory through different ways, making it easier to handle records and improves the working of program.
    • Effective Memory Management: 8086 functions efficiently as memory management, such as it divides memory into segments, allowing for easy access to specific locations, which improves the memory usage and making it more efficient.
    • Wide Range of Uses: The 8086 finds its use in wide range of devices, ranging between personal computers and industrial machines, leading to wide support, tools, and software resources.

    No comments:

    Post a Comment

    Desktop Virtualisation

    Desktop Virtualization ( DV ) Desktop Virtualization ( DV ) is a technique that creates an illusion of a desktop provided to the user. It d...