In DOS, exactly how many bytes is the High Memory Area (HMA), and why isn't it a full 64K?
In DOS, exactly how many bytes is the High Memory Area (HMA), and why isn't it a full 64K?
In DOS, exactly how many bytes is the High Memory Area (HMA), and why isn't it a full 64K?
The High Memory Area is 65,520 bytes (64 KiB minus 16 bytes), not a full 65,536 bytes.
Why 16 bytes short:
The HMA is an artifact of real-mode segment:offset addressing on the 80286 and later. In real mode a physical address is computed as segment x 16 + offset. The highest possible segment value is FFFF, which gives a base of FFFF x 16 = 0xFFFF0 (1,048,560 - that is, 16 bytes below the 1 MB / 0x100000 line).
A 16-bit offset spans 0x0000-0xFFFF, so segment FFFF can reach from 0xFFFF0 up to 0xFFFF0 + 0xFFFF = 0x10FFEF. The part of that window lying above the 1 MB mark runs from 0x100000 to 0x10FFEF - exactly 65,520 bytes. The first 16 bytes of the segment (offsets 0x0000-0x000F, linear 0xFFFF0-0xFFFFF) sit just below 1 MB and belong to conventional memory, so they are not counted as part of the HMA. Hence 65,536 - 16 = 65,520, and the HMA addresses run FFFF:0010 through FFFF:FFFF.
Why the region is reachable at all (the A20 gate):
On the original 8086/8088, with only 20 address lines, an address like FFFF:0010 had no 21st line to carry into, so it wrapped around to 0x00000. Some DOS-era programs depended on this wraparound. When the 80286 added more address lines, IBM kept compatibility by adding a logic gate (originally driven through the keyboard controller) that could force address line A20 off, emulating the old wrap. Enabling A20 (via an A20 handler such as HIMEM.SYS) lets segment FFFF actually reach above 1 MB, exposing those 65,520 bytes. DOS could then load part of itself there with DOS=HIGH, freeing conventional memory.
So the size is a direct consequence of the arithmetic: the topmost real-mode segment starts 16 bytes below 1 MB, so only 64K - 16 = 65,520 bytes of it lie in the extended-memory region above the megabyte boundary.</answer>
Sources: