x86intelx86-16memory-addressreal-mode

What happens when the physical address corresponding to CS:IP is more than 20 bits in 8086?


In 8086 microprocessor, suppose CS is FFFFH and IP is FAB0H Then the physical memory address would be computed by multiplying CS by 16 and adding IP. i.e. Add = FFFF0 + FAB0 This sum gives an overflow as the sum cannot be stored in 20 bits. What will happen?


Solution

  • For 8086 the result will be truncated to fit in 20 bits; causing it to wrap around. For example 0xFFFF0 + 0xFAB0 = 0x10FAA0 = 0xFAA0. The segmented address that points above 1 MiB then actually accesses memory in the first 64 KiB - 16 Bytes.

    Newer 80x86 CPUs (starting with 80286) support wider physical addresses and don't truncate; but to uphold backward compatibility the old behavior was simulated by having a programmable "A20 gate" (that was originally outside the CPU) to mask off the 21st address bit (A20) if "A20 gate" is disabled. Because of this, for newer CPUs with "A20 gate" enabled, you can access almost 64 KiB more physical address space in real mode (up to 0xFFFF:0xFFFF = 0x10FFEF, or 65520 bytes more than the original 1 MiB). This is called the High Memory Area.