8086 memory segmentation
Compact, exam-focused notes on 8086 memory segmentation: how segment:offset addresses translate to 20-bit physical addresses, rules, examples and common exam traps.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
8086 memory segmentation is the scheme the 8086 CPU used to access its physical memory. Engineers use it when designing low-level system software (boot loaders, BIOS, OS real-mode code), writing assembly, and when explaining legacy behaviour (memory wrap-around, overlapping segments) that affects compatibility with later x86 processors.
Key ideas
Start with definitions (each defined term in bold the first time it appears):
- Segment: a 16-bit value stored in a segment register that represents the base of a memory region in 8086 real mode. The segment value is not an absolute byte address; it is combined with an offset to produce a physical address.
- Offset: a 16-bit value that gives the byte displacement from the segment base to the target byte inside that segment.
- Logical address (also called segment:offset): the pair written as
segment:offset(for example 1234h:5678h). This shows the segment register used and the offset inside it. - Physical address: the 20-bit byte address on the 8086 address bus obtained from a logical address by Segment×16 + Offset. Note: on 8086, the term effective address (EA) refers to the 16-bit offset computed by the addressing mode before adding the segment base.
- Segment register: one of the CPU registers that hold a 16-bit segment value. The four segment registers on 8086 are CS (Code Segment), DS (Data Segment), SS (Stack Segment) and ES (Extra Segment).
- IP (Instruction Pointer): a 16-bit register that holds the offset within CS for the next instruction. SP/BP/SI/DI are 16-bit general-purpose registers commonly used as offsets for memory addressing.
Basic law (the address translation rule used by exam questions):
- To compute a 20-bit physical address from a logical address: multiply the 16-bit segment value by 16 (i.e. shift left by 4 bits) and add the 16-bit offset. The result is truncated to the low 20 bits by the 8086 physical address bus.
Consequences and assumptions often asked in exams:
- The 8086 has a 20-bit address bus, so it can address at most 2^20 = 1,048,576 bytes (1 MB). Valid physical addresses are 0x00000 to 0xFFFFF.
- A segment can span up to 64 KiB (because offset is 16-bit). So the maximum size of a logical segment is 65,536 bytes (offsets 0x0000..0xFFFF).
- Because the segment base is only aligned to 16-byte boundaries (multiplying by 16), segments can and do overlap. Different segment:offset pairs can produce the same physical address.
- If the arithmetic gives a value greater than 0xFFFFF, the 8086 hardware had only 20 address lines, so the address effectively wrapped modulo 2^20. That wrap-around is part of the original 8086 behaviour (later PC systems introduced mechanisms like the A20 gate for compatibility reasons). On 8086/8088, after RESET execution begins at physical address 0xFFFF0 (CS:IP = FFFFh:0000h). On IBM PC/AT–class machines, the system’s A20 gate can force address line A20 low to emulate this wrap-around in real mode.
Default segment selection rules (what segment register is used when the assembler or instruction omits the segment):
- For most data memory references, DS is the default segment.
- If the effective address uses BP (base pointer), the default segment is SS (stack segment) because BP usually refers to stack data.
- Stack operations (PUSH, POP, CALL, RET, and direct stack memory access) use SS.
- String instructions: source addresses use DS:SI by default; destination addresses use ES:DI (for example, MOVS copies from DS:SI to ES:DI; LODS reads from DS:SI; STOS writes to ES:DI). A segment override prefix (CS:, DS:, ES:, or SS:) can change the default for most memory operands; the destination of string instructions always uses ES and cannot be overridden.
What diagrams to draw in an exam when asked: draw a horizontal linear memory bar labelled 0x00000 to 0xFFFFF. Mark a segment base at address (Segment × 16) and show offsets 0x0000 to 0xFFFF extending from that base. Draw a second segment whose base is 16 bytes earlier to illustrate overlap. Label CS:IP, DS:[offset], SS:[offset] examples.
Note: Verified details included above — on 8086/8088 reset starts at physical 0xFFFF0 with CS:IP = FFFFh:0000h; IBM PC/AT–class systems provide an A20 gate to emulate wrap-around in real mode.
Formulas
Physical = Segment × 16 + Offset — Segment and Offset are 16-bit values (hex or decimal). Physical is a 20-bit address (bytes). Applies on 8086 real mode.
Max physical address = 2^20 - 1 = 1048575 (decimal) = 0xFFFFF — maximum byte address on the 8086 bus.
Maximum segment span = 2^16 = 65536 bytes (0x10000) — size determined by 16-bit offset range (0x0000..0xFFFF).
Number of distinct segment:offset pairs that can map to the same physical address = 65536 / 16 = 4096 — derivation: for a given physical address A, S must satisfy 0 ≤ A − 16·S ≤ 0xFFFF; integer count equals floor(65535/16)+1 = 4096.
Worked examples
Example 1 — straightforward translation (hex):
Given: CS = 1234h, IP = 5678h. Compute physical address of the instruction byte at CS:IP.
Step 1 (formula): Physical = Segment × 16 + Offset
Step 2: Segment × 16 = 1234h × 10h = 12340h
Step 3: Add offset: 12340h + 5678h = 179B8h
Step 4: Check range: 179B8h ≤ FFFFFh, so no wrap-around.
Answer: Physical address = 179B8h (decimal 96,696). (Show as CS:IP = 1234h:5678h → physical 179B8h.)
Example 2 — wrap-around demonstration:
Given: Segment = FFFFh, Offset = 0010h. Compute physical.
Segment × 16 = FFFFh × 10h = FFFF0h
Add offset: FFFF0h + 0010h = 100000h
But 8086 has only 20 address lines, so physical address is low 20 bits: 100000h modulo 100000h = 00000h. That is wrap-around to the start of memory.
Answer: Physical address = 00000h (wrap-around). This shows why boot vectors and compatibility concerns exist.
Example 3 — how many segment:offset pairs map to the same physical address:
Given a physical address A, S must satisfy 0 ≤ A − 16·S ≤ 0xFFFF. Rearranged:
(A − 0xFFFF)/16 ≤ S ≤ A/16.
Number of integer S values = floor(A/16) − ceil((A − 0xFFFF)/16) + 1 = 4096 in general.
Thus up to 4096 different segment values S give a valid 16-bit offset producing the same physical A; each gives a distinct segment:offset pair. Example: 0000h:0010h and 0001h:0000h both map to physical address 00010h.
Common mistakes
- Thinking a segment register contains the full 20-bit base address. It stores a 16-bit value; the base is Segment × 16.
- Ignoring wrap-around above 0xFFFFF. If the sum exceeds 20 bits, the 8086 hardware uses the low 20 bits.
- Wrong default segment choice: e.g., using DS when BP is used in the effective address — correct default is SS for BP-based addresses.
- Mixing up which segment is used for string instructions: destination is ES:DI (write), source is DS:SI (read).
For your exam
Typical question types:
- Definitions and short notes (define segment, logical vs physical address, role of CS/DS/SS/ES).
- Derivations (show how segment×16 + offset produces the 20-bit address; derive number of segment:offset pairs mapping to the same physical address).
- Numerical problems (compute physical addresses, show wrap-around, compute overlap examples).
- Diagrams (draw memory from 0x00000 to 0xFFFFF; show one or two segments and offsets; label CS:IP and stack uses).
What full-mark answers should include:
- For definitions: clear, short definition with example (e.g., give a sample segment:offset).
- For derivations: show the formula step-by-step, mention the 20-bit bus limit and the 64 KiB offset limit.
- For numericals: write the formula, show the multiply-by-16 step explicitly, add offset, and check for wrap-around; present final answer in hex (and decimal if asked).
- For diagrams: a linear memory bar with addresses, base = Segment×16 labelled, offset range 0..0xFFFF, and at least one overlapping segment example.
Quick check
- Compute physical address for DS = 0x2000 and offset = 0x1234.
- Which segment register is used by default for memory references using BP?
- How many different segment:offset pairs can map to the same physical address on the 8086?
Answers: 1) 0x2000×16 + 0x1234 = 0x20000 + 0x1234 = 0x21234. 2) SS (Stack Segment). 3) 4096.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?