Microprocessor 8086 Addressing mode Lab Manual
what is assembly language?
Assembly language is a low-level programming language. You need to get some knowledge
about computer structure in order to understand anything. The simple computer model as I see it:
The system bus (shown in yellow) connects the various components of a computer.
The CPU is the heart of the computer, most of computations occur inside the CPU.
RAM is a place to where the programs are loaded in order to be executed.
Inside Microprocessor (CPU)
general purpose registers
8086 CPU has 8 general purpose registers, each register has its own name:
AX - the accumulator register (divided into AH / AL).
BX - the base address register (divided into BH / BL).
CX - the count register (divided into CH / CL).
DX - the data register (divided into DH / DL).
SI - source index register.
DI - destination index register.
BP - base pointer.
SP - stack pointer.
The size of the above registers is 16 bit, it's something like: 0011000000111001b (in binary
form).
4 general purpose registers (AX, BX, CX, DX) are made of two separates 8-bit registers, for
example if AX= 0011000000111001b, then AH=00110000b and AL=00111001b.
Therefore, when you modify any of the 8-bit registers 16-bit register is also updated, and vice-
versa. The same is for other 3 registers, "H" is for high and "L" is for low part.
Because registers are located inside the CPU, they are much faster than memory. Accessing a
memory location requires the use of a system bus, so it takes much longer. Accessing data in a
register usually takes no time. Therefore, you should try to keep variables in the registers.
Register sets are very small and most registers have special Purposes which limit their use as
variables, but they are still an excellent place to store temporary data of calculations.
Segment registers
CS - points at the segment containing the current program.
DS - generally points at segment where variables are defined.
ES - extra segment register, it's up to a coder to define its usage.
SS - points at the segment containing the stack.
Although it is possible to store any data in the segment registers, this is never a good idea. The
segment registers have a very special purpose - pointing at accessible blocks of memory.
Segment registers work together with general purpose register to access any memory value.
For example, if we would like to access memory at the physical address 12345h (hexadecimal),
we should set the DS = 1230h and SI = 0045h. This is good, since this way we can access much
more memory than with a single register that is limited to 16-bit values.
CPU makes a calculation of physical address by multiplying the segment register by 10h and
adding general purpose register to it (1230h * 10h + 45h = 12345h):
The address formed with 2 registers is called an effective address. By default, BX,
SI and DI registers work with DS segment register; BP and SP work with SS segment register.
Other general-purpose registers cannot form an effective address! also, although BX can form an
effective address, BH and BL cannot.
Special purpose registers
IP - the instruction pointer.
flags register - determines the current state of the microprocessor.
IP register always works together with CS segment register and it points to currently
executing instruction.
Flags register is modified automatically by CPU after mathematical operations, this
allows to determine the type of the result, and to determine conditions to transfer control
to other parts of the program.
Generally you cannot access these registers directly, the way you can access AX and other
general registers, but it is possible to change values of system registers using some tricks that
you will learn a little bit later.
Memory Access
To access memory we can use these four registers: BX, SI, DI, BP. Combining these registers
inside [ ] symbols, we can get different memory locations.
These combinations are supported (addressing modes):
d8 - stays for 8-bit signed immediate displacement (for example: 22, 55h, -1)
d16 - stays for 16-bit signed immediate displacement (for example: 300, 5517h, -259).
Displacement can be an immediate value or offset of a variable, or even both. If there are
several values, assembler evaluates all values and calculates a single immediate value.
Displacement can be inside or outside of the [ ] symbols, assembler generates the same
machine code for both ways. Displacement is a signed value, so it can be both positive or
negative.
Generally the compiler takes care about difference between d8 and d16, and generates the
required machine code. For example, let's assume that DS = 100, BX = 30, SI = 70. The
following addressing mode: [BX + SI] + 25 Is calculated by processor to this physical
address: 100 * 16 + 30 + 70 + 25 = 1725. By default, DS segment register is used for all modes
except those with BP register, for this SS segment register is used. There is an easy way to
remember all those possible combinations using this chart:
All valid combinations can be formed by taking only one item from each column or skipping the
column by not taking anything from it. BX and BP never go together. Neither SI and DI do.
Examples of valid addressing modes:
[BX+5]
[BX+SI]
[DI+BX-4]
The value in segment register (CS, DS, SS, ES) is called a segment, and the value in general
purpose register (BX, SI, DI, BP) is called an offset.
When DS contains value 1234h and SI contains the value 7890h it can be also recorded
as 1234:7890. The physical address will be 1234h * 10h + 7890h = 19BD0h.
If zero is added to a decimal number it is multiplied by 10, however 10h = 16, so If zero is
added to a hexadecimal value, it is multiplied by 16, for example:
7h = 7
70h = 112
LAB Practice
This lab will demonstrate different 8086 addressing modes using emu8086. Each mode serves a
specific purpose in accessing data efficiently. Practicing these modes helps in better
understanding memory and register operations in 8086 assembly language.
Objective
To understand and implement different addressing modes of the 8086 microprocessor
using emu8086.
To write assembly programs demonstrating each addressing mode.
Theory
8086 supports different addressing modes that determine how operands are accessed. The main
categories are:
1. Immediate Addressing Mode
2. Register Addressing Mode
3. Direct Addressing Mode
4. Indirect Addressing Mode
5. Indexed Addressing Mode
6. Base Addressing Mode
7. Base-Indexed Addressing Mode
8. Base-Indexed with Displacement Mode
Each mode helps in accessing data from different sources efficiently.
1. Download Emmu8086 from
https://emu8086-microprocessor-emulator.en.softonic.com/download
2. Install on your computer
3. After installation double click on the emmu8086 icon and you will get the following
window. Close the po up sub window.
Emulator 8086 screen
Immediate addressing mode
Register addressing mode
Direct Addressing mode
Indirect addressing mode
MOV [2000H], 55H; Stores the value 55H in memory location 2000H.
MOV BX, 2000H; Stores the address 2000H in register BX.
Now, BX acts as a pointer to memory.
MOV AL, [BX]; Retrieves the value stored at memory location [BX] (2000H) and loads it
into AL.
Since 2000H contains 55H, after execution, AL = 55H
Indexed Addressing mode
Base register addressing mode
1. Store 1234H at memory location 2010H.
2. Load BX = 2000H, making BX the base register.
3. MOV AX, [BX + 10H] → Effective Address = 2000H + 10H = 2010H, so AX = 1234H.
1. Set SS = 1000H.
2. Load BP = 0020H (base address) and SI = 0005H (index).
3. Store 78H at [BP + SI] → SS:0025H.
4. Load AL from SS:0025H, so AL = 78H.
Key Differences
Addressing Mode Formula Example Usage
Base + [Base + Offset] MOV AX, [BX + 10H] Array access
Displacement
Base + Index [Base + Index] MOV AL, [BP + SI] Stack/Array
Instruction set of 8086
Objective
This lab manual provides an introduction to the instruction set of the 8086 microprocessor with
illustrative examples using emu8086. It covers data transfer, arithmetic, logical, branching, and
stack operations.
1. Data Transfer Instructions
These instructions move data between registers, memory, and I/O ports.
Example 1: Moving Immediate Data into Register
Example 2: Memory to Register Transfer
Example 3: XCHG instruction
This instruction used to swap the value of two memory location or registers.
2. Arithmetic Instructions
These instructions perform addition, subtraction, multiplication, and division.
Example 3: Addition
Example 4: Subtraction
Example 5: Multiplication
Example 6: Division
Step-by-Step Explanation
1. MOV AX, 1000H
The instruction MOV AX, 1000H loads the hexadecimal value 1000H (4096 in decimal)
into the AX register.
After execution: AX = 1000H (4096 decimal)
2. MOV CX, 04H
The instruction MOV CX, 04H loads the hexadecimal value 04H (4 in decimal) into the
CX register.
After execution: CX = 04H (4 decimal)
3. DIV CX
DIV is the division instruction in 8086 for unsigned division.
The DIV instruction works differently based on the operand size:
o If the divisor is a register/memory (16-bit value) (like CX here), then the
dividend is taken from DX:AX (32-bit pair).
o If the divisor is an 8-bit value, then the dividend is only in AX.
How division works in this case:
Here, CX = 04H (4 in decimal), which is a 16-bit divisor.
The dividend is taken from AX (since DX is implicitly assumed as 0000H in this case).
DIV CX means:
(DX:AX) ÷ CX → (0000 1000H) ÷ (0004H)
o 00001000H (4096 decimal) ÷ 0004H (4 decimal) = 1024 decimal (0400H)
o The quotient is stored in AX.
o The remainder is stored in DX.
Final Register Values:
AX = 0400H (1024 decimal) → Quotient
DX = 0000H (0 decimal) → Remainder
Summary
The code performs 4096 ÷ 4 = 1024 using the DIV instruction.
The quotient (1024 or 0400H) is stored in AX.
The remainder (0) is stored in DX
Logical Instructions
NOT instruction
AND instruction
OR instruction
XOR instruction
SHL – shift left instruction: multiplying by 2
SHR – shift right: dividing by 2
ROL – rotate left
ROR – rotate right
Control transfer instructions