1. Logical and Physical Addresses
Definition – Two-stage address formation
- Effective-address (EA) calculation produces a 16-bit offset.
- A segment register supplies the segment value.
- The result is 20 bits → selects one byte in a 1 MB () address space.
- A logical address is written
segment:offset, e.g.DS:0120h.
2. Physical-Address Example
Worked example – DS = 2400h, SI = 0120h
- Logical address:
DS:0120h→ Physical address:24120h. - The segment value is shifted left by 4 bits (one hex digit) before the addition.
⚠️ Many logical addresses map to the same physical byte: 2412h:0000h is also 24120h.
3. Immediate Operands
Definition
A constant encoded in the instruction; it has no runtime memory address.
mov ax, 25
mov al, 0FFh
add bx, 4
cmp cx, 100- NASM uses no
#prefix. - The destination determines the width here (AL → byte, AX → word).
4. Register Operands
Definition
The operand is already inside the CPU — no memory data transfer.
mov ax, bx
add dx, cx
xor al, ah
inc si- Both operands must have compatible widths.
⚠️ Segment-register restrictions: no immediate into a segment register, no segment-to-segment MOV, and CS cannot be a MOV destination.
5. Direct Memory Addressing
Definition
The instruction contains a displacement (the label’s offset).
mov ax, [total]
mov [result], ax
mov al, [status]- The assembler encodes the label offset; DS is the default segment.
- Brackets request the contents at that address.
6. Register-Indirect Addressing
Definition
One register supplies the offset.
| Form | Role | Default segment |
|---|---|---|
[BX] | Base | DS |
[BP] | Base (stack) | SS |
[SI] | Source index | DS |
[DI] | Destination index | DS |
The other operand decides byte vs word access (mov al,[si] vs mov ax,[si]).
7. Based Addressing
Definition
mov ax, [bx+4]
mov ax, [bp+6]
mov al, [bx+recordField]
mov ax, [bp+parameterOffset]BX-based → DS;BP-based → SS.- The displacement is an encoded constant.
8. Indexed Addressing
Definition
mov al, [si+2]
mov al, [di+10]
mov al, [array+si] ; array = displacement, SI = element offset
mov al, [table+di]- Designed for sequential data access: the program changes SI/DI between elements.
9. Based-Indexed Addressing
Definition
| Legal pairs | Default segment |
|---|---|
[BX+SI], [BX+DI] | DS |
[BP+SI], [BP+DI] | SS |
⚠️ Invalid: [BX+BP] (two bases), [SI+DI] (two indexes). The 8086 encoding permits at most one base and one index.
10. Displacement with Based-Indexed Addressing
Definition
mov ax, [bx+si+8]
mov ax, [bp+di+field]
mov al, [array+bx+si]- If
BPappears → SS; otherwise → DS.
11. Effective-Address Trace
Worked example – BX = 1000h, SI = 0020h, disp = 4, DS = 2000h
mov ax, [bx+si+4]| Step | Calculation | Result |
|---|---|---|
| 1. Legal form? | BX + SI | ✓ |
| 2. EA | 1000h + 0020h + 0004h | 1024h |
| 3. Segment | no BP → DS | 2000h |
| 4. Physical | 20000h + 1024h | 21024h |
| 5. Size | destination AX | word (21024h, 21025h) |
flowchart LR A["BX + SI + disp"] --> B["EA = 1024h"] C["DS = 2000h → ×16 = 20000h"] --> D B --> D["PA = 21024h"]
⚠️ Always compute the effective offset first, then the physical address.
12. Default Segment Rules
Reference table
| Access | Default segment |
|---|---|
| Instruction fetch | CS:IP |
PUSH, POP, anything using SP | SS |
Memory operand containing BP | SS |
| Most other data operands | DS |
String destination (DI) | ES |
A segment override can select another segment (except for instruction fetch, stack operations and string destinations).
13. Segment Override
Definition
A prefix that replaces the default segment for one instruction.
mov ax, [es:di]
mov al, [cs:table+si] ; table stored in the code segment
mov [ss:bx], dx⚠️ Use an override only when the data genuinely lives elsewhere — the prefix adds a byte and can cost time.
14. Byte and Word Transfers
Definition – Little-endian order
An address identifies one byte; a word occupies two consecutive bytes, low byte first.
| Instruction | Bytes read | Pointer update |
|---|---|---|
mov al,[si] | 1 | inc si |
mov ax,[si] | 2 | add si,2 |
Worked example – word 1234h stored at offset 0100h
| Offset | 0100h | 0101h |
|---|---|---|
| Content | 34h (low) | 12h (high) |
mov al,[0100h] → AL = 34h; mov ax,[0100h] → AX = 1234h.
⚠️ The 8086 has only byte and word operands — a 32-bit value needs multiple operations.
15. Adding Two 24-bit Numbers
Worked example – byte-wise carry chain
; P and Q stored low byte first
mov al, [P]
add al, [Q] ; byte 0: ADD
mov [R], al
mov al, [P+1]
adc al, [Q+1] ; byte 1: ADC
mov [R+1], al
mov al, [P+2]
adc al, [Q+2] ; byte 2: ADC
mov [R+2], alNumeric trace: (stored FF FF 01), (stored 01 00 00).
| Byte | Operation | Result | CF out |
|---|---|---|---|
| 0 | FFh + 01h | 00h | 1 |
| 1 | FFh + 00h + 1 | 00h | 1 |
| 2 | 01h + 00h + 1 | 02h | 0 |
✓
flowchart LR B0["ADD byte 0"] -- CF --> B1["ADC byte 1"] -- CF --> B2["ADC byte 2"]
💡 MOV does not touch CF, so the mov instructions between stages are safe.
⚠️ No flag-changing instruction may appear between the stages.
16. Address Calculation with LEA
Definition – LEA
LEA reg, [expr] stores the effective offset of expr in reg without reading memory.
lea si, [table]
lea bx, [array+4]
lea di, [bx+si+8]- FLAGS unchanged.
- Destination must be a general 16-bit register.
Worked example – BX = 1000h, SI = 0020h
| Instruction | Result |
|---|---|
lea di,[bx+si+8] | DI = 1028h (the address) |
mov di,[bx+si+8] | DI = word stored at DS:1028h |
💡 LEA doubles as cheap arithmetic: lea ax,[bx+si+8] computes BX+SI+8 in one instruction.
17. Array Traversal
Worked example – sum 16 unsigned bytes into a word
mov si, array
mov cx, 16
xor ax, ax ; word total = 0
next:
mov bl, [si]
xor bh, bh ; zero-extend byte → BX
add ax, bx
inc si ; next byte
loop next
mov [sum], axflowchart TD I["SI ← array, CX ← 16, AX ← 0"] --> R["BX ← zero-extended [SI]"] R --> A["AX ← AX + BX; SI ← SI + 1"] A --> L{"--CX ≠ 0 ?"} L -- yes --> R L -- no --> S["[sum] ← AX"]
- SI points to the current byte; CX gives exactly 16 iterations.
- A word total avoids overflow (max ).
⚠️ add ax,bl is illegal — the byte must be zero-extended first.
18. Lookup Tables
Definition – Index to offset
| Table type | Offset |
|---|---|
| Byte table | |
| Word table |
- Use an unsigned byte as the entry number and zero-extend it.
⚠️ The 8086 has no scaled-index addressing ([si+bx*2] is illegal) — scale manually with SHL.
19. Word Lookup Table
Worked example – AX ← table[index]
xor bx, bx ; clear BH (avoid stale bits)
mov bl, [index]
shl bx, 1 ; ×2 → byte offset
mov si, table
mov ax, [si+bx] ; legal pair BX+SITrace with index = 3, table at offset 0200h:
| Step | BX | SI | Address read |
|---|---|---|---|
mov bl,[index] | 0003h | — | — |
shl bx,1 | 0006h | — | — |
mov ax,[si+bx] | 0006h | 0200h | 0206h (entry 3) |
20. Record Fields
Definition – Base + field displacement
A record’s fields are accessed as [base + fieldOffset], with offsets defined by equ.
person_age equ 0 ; byte
person_id equ 2 ; word
person_score equ 4 ; word
mov bx, person
mov al, [bx+person_age]
mov ax, [bx+person_id]| Offset | 0 | 1 | 2–3 | 4–5 |
|---|---|---|---|---|
| Field | age | (unused) | id | score |
💡 equ constants describe byte offsets; they allocate no storage.
21. Linked Structures
Definition – Pointer-based node
Each node holds data plus a 16-bit offset to the next node; a null value (e.g. 0) ends the list.
mov bx, head
walk:
test bx, bx ; null? (if 0 is the null convention)
jz done
; ... process node at BX ...
mov ax, [bx+nextField] ; read next pointer
mov bx, ax ; advance
jmp walk
done:flowchart LR H[head] --> N1["data | next"] --> N2["data | next"] --> N3["data | next"] --> Z[null]
22. Post-Increment Conversion
68K → 8086 mapping
| 68K | 8086 equivalent |
|---|---|
move.b (A0)+,D0 | mov al,[si] + inc si |
move.w (A0)+,D0 | mov ax,[si] + add si,2 |
| (string form) | lodsb – loads DS:SI into AL and updates SI by DF |
⚠️ The 8086 has no general post-increment mode — the update is a separate instruction.
23. Pre-Decrement Conversion
68K → 8086 mapping
| 68K | 8086 equivalent |
|---|---|
move.w D0,-(A7) | push ax (SP ← SP − 2, then store) |
move.w -(A0),D0 | sub si,2 + mov ax,[si] |
⚠️ The decrement size must match the data (1 for bytes, 2 for words).
24. String Addressing
Definition – Implicit source/destination
| Instruction | Operation | Pointers updated |
|---|---|---|
LODSB | AL ← DS:[SI] | SI |
STOSB | ES:[DI] ← AL | DI |
MOVSB | ES:[DI] ← DS:[SI] | SI, DI |
(Word versions LODSW, STOSW, MOVSW use AX and step by 2.)
| DF | Set by | Direction |
|---|---|---|
| 0 | CLD | SI/DI increase |
| 1 | STD | SI/DI decrease |
REP repeats the instruction CX times.
25. Forward Block Copy
Worked example – copy 32 bytes
cld ; forward
mov si, source ; DS:SI = source
mov di, destination ; ES:DI = destination
mov cx, 32
rep movsbflowchart LR S["DS:SI (source)"] -- "MOVSB × CX" --> D["ES:DI (destination)"]
- In a
.COMprogram DS = ES at startup, so both labels resolve in the same segment.
⚠️ Overlapping blocks where destination > source must be copied backward (STD, pointers at the last byte) or data is overwritten before it is read.
26. Stack Addressing
Definition – PUSH / POP
| Instruction | Operation |
|---|---|
PUSH src | , then |
POP dst | , then |
Worked example – near procedure frame
push param ; caller
call proc
...
proc:
push bp
mov bp, sp
mov ax, [bp+4] ; caller-supplied word| Address | Contents |
|---|---|
BP+4 | parameter |
BP+2 | return address (pushed by CALL) |
BP+0 | saved old BP |
- BP gives stable access while SP keeps moving;
[BP+…]defaults to SS.
27. Relative Control Transfer
Definition – Displacement-encoded branch
| Branch | Displacement | Range |
|---|---|---|
| Short / conditional jump | 8-bit signed | −128 … +127 |
Near JMP, CALL | 16-bit | whole segment |
Worked example
jeat 0100h (2 bytes), target 0110h → next = 0102h → disp = 0110h − 0102h = 0Eh.loopat 0105h (2 bytes), target 0100h → next = 0107h → disp = −7 = F9h.
💡 Relative encoding means code still works when relocated within a segment. Let the assembler compute displacements.
⚠️ On the 8086, Jcc is short only — a target beyond ±127 bytes needs an inverted Jcc over a JMP.
28. Permitted Combinations
Reference table – original 8086 effective addresses
| Valid | Invalid |
|---|---|
[BX], [BP], [SI], [DI] | [AX], [CX], [DX] |
[BX+SI], [BX+DI], [BP+SI], [BP+DI] | [SP] |
| Any of the above + displacement | [BX+BP] (two bases) |
[disp] (direct) | [SI+DI] (two indexes) |
[BX+SI+DI] (three registers) |
💡 Mnemonic: at most one from {BX, BP} + at most one from {SI, DI} + optional displacement.
29. Exercises
Exercise 1 – Address calculation
DS = 1200h, BX = 0100h, SI = 0020h, MOV AX,[BX+SI+4].
| Quantity | Value |
|---|---|
| Effective offset | 0100h + 0020h + 0004h = 0124h |
| Default segment | DS (no BP) |
| Physical address | 12000h + 0124h = 12124h |
| Bytes read | 2 (12124h and 12125h) |
Exercise 2 – Word-array access
Load W[i] into AX (W = 20 words, i = unsigned byte, DS already set).
xor bx, bx ; zero extension → no stale BH bits
mov bl, [i]
shl bx, 1 ; element index → byte offset
mov si, W
mov ax, [si+bx] ; legal SI+BX pair, word load