8086 Execution Unit
8086 Execution Unit
8086 Execution Unit
Relative addressing mode is a method used in assembly language programming for specifying the
operand's address. It involves providing an offset value relative to a base address, which is typically
the address of the current instruction or a register. This addressing mode is particularly useful for
branch instructions and memory access patterns that depend on the current program counter (PC) or
another reference point.
sql
BR offset
If the current PC is at address `1000` and the instruction is `BR 4`, the processor will add `4` to
the current PC, resulting in the new PC value `1004`.
Here’s a simple example in an assembly language syntax (like that used in ARM or MIPS processors):
assembly
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 1/12
In this example:
Advantages:
Efficient Looping and Branching: Ideal for implementing loops and conditional jumps.
Code Portability: Makes the code more position-independent, as the actual addresses are not
hard-coded.
Memory Efficient: Saves memory as the offset is often smaller than absolute addresses.
Disadvantages:
Limited Range: The offset typically has a limited range, which may restrict the distance between
the instruction and the target address.
Complexity in Address Calculation: May add complexity to the address calculation logic within
the CPU.
Practical Application:
Relative addressing is commonly used in modern CPUs for implementing various control flow
instructions, such as:
Understanding relative addressing mode is crucial for low-level programming and for developers
working on compiler design, embedded systems, and performance-critical applications.
Relative addressing mode is a way of specifying the location of an operand in assembly language by
providing an offset relative to a base address, typically the current program counter (PC). This mode is
commonly used for branching instructions, where the offset is added to the PC to determine the
target address for the jump.
i can't understand
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 2/12
Relative addressing mode specifies the location of data by giving an offset (difference) from the
current instruction's address. Instead of using an absolute memory address, it tells the processor to
go a certain distance forward or backward from where it is now.
Simple Definition:
Relative addressing mode uses an offset to determine the address of the data relative to the current
position in the program. This is often used in branch instructions to jump to a new instruction a
certain number of steps away.
Example:
Imagine you are on step 5 of a list, and you have an instruction that says, "Go forward 3 steps." In
relative addressing mode, you would go from step 5 to step 8.
Similarly, if the current instruction is at memory address 100, and the offset is 4, the new address will
be 100 + 4 = 104.
In the 8086 microprocessor, subroutines (also known as procedures or functions) are blocks of code
that perform a specific task and can be called from different places in the program. The main
instructions associated with subroutines in the 8086 microprocessor are `CALL` and `RET`.
CALL Instruction
1. Saves the address of the next instruction (the return address) onto the stack.
2. Transfers control to the subroutine by jumping to its starting address.
objectivec
CALL subroutine_address
or
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 3/12
objectivec
CALL subroutine_label
RET Instruction
The `RET` instruction is used to return from a subroutine. It does the following:
RET
Example
Here is an example demonstrating how to use `CALL` and `RET` instructions in an assembly language
program for the 8086 microprocessor:
assembly
segment .data
message db 'Hello, World!', 0
segment .text
global _start
_start:
; Call the subroutine
CALL print_message
print_message:
; Display the message
MOV DX, offset message ; Load address of message into DX
MOV AH, 09h ; DOS print string function
INT 21h ; Call DOS interrupt to print string
Explanation
1. Main Program:
The `CALL print_message` instruction calls the `print_message` subroutine.
The return address (next instruction after `CALL`) is pushed onto the stack.
The control is transferred to the `print_message` subroutine.
2. Subroutine (print_message):
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 4/12
The subroutine prints a message by using DOS interrupt 21h with function 09h.
After printing the message, the `RET` instruction is executed.
The return address is popped from the stack, and control is transferred back to the main
program, right after the `CALL` instruction.
Stack Operations
Nested Subroutines
Subroutines can call other subroutines. In such cases, each `CALL` pushes a return address onto the
stack, and each `RET` pops an address from the stack. The stack ensures that each subroutine returns
to the correct location.
Summary
`CALL`: Used to call a subroutine, pushing the return address onto the stack.
`RET`: Used to return from a subroutine, popping the return address from the stack.
Understanding how to use `CALL` and `RET` effectively allows for modular and reusable code in
assembly language programming.
The 8086 microprocessor instruction set includes a variety of instructions for performing different
operations. These instructions can be broadly classified into several categories, including data
transfer, arithmetic, logical, control transfer, string manipulation, and processor control instructions.
Below is a detailed and simple explanation of each category along with examples.
These instructions move data between registers, between memory and registers, or between I/O
ports and registers.
css
MOV AX, BX ; AX = BX
MOV [SI], AX ; Memory at address SI = AX
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 5/12
PUSH: Push data onto the stack.
mathematica
PUSH AX ; Stack = AX
mathematica
POP AX ; AX = Stack
csharp
java
2. Arithmetic Instructions
These instructions perform arithmetic operations like addition, subtraction, multiplication, and
division.
sql
ADD AX, BX ; AX = AX + BX
vbnet
SUB AX, BX ; AX = AX - BX
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 6/12
arduino
css
3. Logical Instructions
These instructions perform bitwise logical operations like AND, OR, XOR, and NOT.
OR AX, BX ; AX = AX OR BX
vbnet
NOT AX ; AX = NOT AX
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 7/12
css
sql
vbnet
css
css
css
vbnet
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 8/12
CMPSW ; Compare word at [SI] with word at [DI]
vbnet
csharp
arduino
yaml
NOP ; No operation
STC ; CF = 1
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 9/12
objectivec
CLC ; CF = 0
objectivec
CMC ; CF = NOT CF
Summary
The 8086 instruction set includes a diverse range of instructions to perform various operations,
including data transfer, arithmetic, logical, control transfer, string manipulation, and processor
control. Understanding these instructions allows for efficient and effective programming of the 8086
microprocessor.
The execution cycle of the 8086 microprocessor involves several stages, during which the processor
fetches, decodes, and executes instructions. Understanding the execution cycle is crucial for
comprehending how the 8086 operates. Here’s a detailed explanation of each stage in the execution
cycle of the 8086 microprocessor:
1. Instruction Fetch
The instruction fetch stage involves retrieving the instruction from memory. The steps are as follows:
1. Program Counter (PC): The PC holds the address of the next instruction to be executed.
2. Address Calculation: The address from the PC is placed on the address bus.
3. Memory Read: The memory read operation is initiated to fetch the instruction.
4. Instruction Queue: The fetched instruction is placed into the instruction queue (a six-byte
prefetch queue to speed up execution).
2. Instruction Decode
The instruction decode stage involves interpreting the fetched instruction to determine what actions
are required. The steps are as follows:
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 10/12
4. Address Calculation: Effective addresses for memory operands are calculated using segment
and offset registers.
3. Execution
The execution stage involves carrying out the actions specified by the decoded instruction. The steps
are as follows:
1. ALU Operations: Arithmetic and logical unit (ALU) performs operations such as addition,
subtraction, AND, OR, etc.
2. Data Transfer: Data is transferred between registers, or between memory and registers.
3. Control Flow Changes: Control flow instructions (like jumps and calls) alter the sequence of
execution.
4. Status Flag Updates: Processor status flags (carry, zero, sign, etc.) are updated based on the
result of the operation.
4. Write Back
The write back stage involves writing the results of the execution back to the destination. The steps
are as follows:
1. Register Update: Results of operations are written back to the appropriate registers.
2. Memory Update: If the operation involves memory, the results are written back to the specified
memory location.
Fetch Stage
The 8086 uses a prefetch queue to fetch instructions ahead of time. This queue can hold up to
six bytes of instructions.
The Bus Interface Unit (BIU) handles fetching the next instruction from memory and placing it
into the queue.
Instruction Pointer (IP) register, combined with the Code Segment (CS) register, forms the
address of the next instruction.
Memory Read Cycle: The BIU sends out the address and reads the instruction byte(s) from
memory.
Decode Stage
The Execution Unit (EU) takes instructions from the prefetch queue.
The instruction is broken down into opcode and operand(s).
The opcode is used to identify the type of operation, while operand(s) provide data or addresses.
ModR/M Byte: For many instructions, an additional byte (ModR/M byte) specifies the addressing
mode and register operands.
If additional operands are required, the EU fetches them from the queue or memory.
Execute Stage
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 11/12
Depending on the instruction, the ALU may perform arithmetic operations (e.g., ADD, SUB),
logical operations (e.g., AND, OR), or data movement (e.g., MOV).
The ALU interacts with registers to perform these operations.
Flags Register: The results of operations may affect the status flags (e.g., zero flag, carry flag).
Results are written back to the destination operand, which could be a register or memory
location.
If the instruction modifies memory, the BIU handles writing data to the correct memory address.
The PC is updated to point to the next instruction, which may involve computing a new address
for jumps or calls.
Additional Concepts
Pipelining
The 8086 employs a simple form of pipelining where instruction fetching and execution overlap. While
one instruction is being executed, the next instruction is being fetched.
Segmentation
The 8086 uses a segmented memory model with four segment registers: CS (Code Segment), DS (Data
Segment), SS (Stack Segment), and ES (Extra Segment). Each segment register holds the starting
address of a segment, which is combined with an offset to form the full address.
sql
ADD AX, BX
1. Fetch: The instruction `ADD AX, BX` is fetched from memory into the prefetch queue.
2. Decode: The instruction is decoded; the opcode identifies it as an ADD operation, and the
operands are AX and BX.
3. Execute: The ALU adds the contents of BX to AX.
4. Write Back: The result is stored in the AX register, and the status flags are updated.
Summary
The 8086 execution cycle involves a series of stages where the processor fetches, decodes, executes,
and writes back instructions. By using a prefetch queue and simple pipelining, the 8086 can overlap
instruction fetch and execution to improve efficiency. Understanding these stages is essential for
grasping how the 8086 microprocessor processes instructions and manages program flow.
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 12/12