16-bit Memory Addressing
The Original PC and the 8086
Here is a very brief explanation of the memory address system used by
DOS. Originally, the IBM-PC used the Intel 8086 processor. This was a
16-bit chip but with the unusual feature that memory was addressed by a
combination of a segment register (16-bit) and an offset register
(16-bit). However, there was no memory protection system, etc, as this
was just an interesting way of providing a bigger memory range than
most 16-bit CPUs. The absolute address was computed from:
segment*16 + offset
Hence with a 16-bit segment register, you could address a total of 1MB
of memory in overlapping 64kB blocks,
a huge amount at the time (~1980). It is common to give memory
addresses in DOS/BIOS applications in the
form [segment:offset] but sometimes you also see it as a linear value,
so the BIOS tick counter at 0040:006C could be shown as 0x046C in the
dosemu source code.
The 8086 had 4 segment registers: CS, DS, SS and ES which were used for
code (with the instruction pointer IP), data (with several registers
possible), stack (with the stack pointer register SP) and an 'extra'
segment that could be paired with several registers, but was optimized
for some tasks such as memory copying, etc.
It also had 4 'general purpose' 16-bit registers, AX, BX, CX and DX,
although they all had some specific special usage (e.g. AX was the
accumulator, etc). These registers could also be used as pairs of
semi-independent 8-bit registers if required (e.g. AH and AL being the
upper and lower 8 bits of AX). In addition, there were some special
offset registers DI and SI that were intended primarily as index
registers for memory access, and had no 8-bit mode.
All of this lead to
problems as memory became cheap & plentiful, and programs grew in
size towards and beyond the 64kB limit. Hence you
would get DOS compilers that had different memory models (and the _near
& _far pointer modifiers), depending on
whether code and/or data size would exceed 64kB, as then segment
manipulation would be needed (slower, and bigger code) to span all of
The 80286 and beyond
Then came the 80286, but alas it did not solve the 64kB segment size
problem! Intel had designed it to cover 16BM in 'protected mode' for
the (then) up and coming OS/2 operating system. The 286 starts in
'real' mode, like an 8086, then you can use a special instruction to
put in 'protected mode' where you then have the sort of protection
mechanism needed for a proper multi-user multi-tasking OS. But still
with the horrible limit of 64kB per segment. Oh, and there was no
instruction to get out of protected mode, you had to halt the CPU and
use a just prepared keyboard interrupt to switch it!
This sorry state continued until the 386 arrived, when at last 32-bit
linear memory models, and proper virtual memory control, were
available. At this point the 16-bit CPU registers became the lower part
of 32-bit ones (e.g. AX being the lower 16-bits of EAX, etc).
Unfortunately, DOS never escaped the 16-bit design and
Microsoft Windows still had 16-bit stuff in it by Windows 98, 12 years
after the 80386 made its appearance!
However, in its defence the 80286 did support protection attributes for
the different segments. For example, you could make the code read-only
and the stack non-executable. Had this been used properly in 1982 most
of the virus/worm problems that plague Microsoft Windows (and, sadly,
others) would not have been possible as you could not use buffer
overflow, etc, to inject hostile code. We now have something like this
with the latest CPU's 'no execute' settings and, for example, XP SP2,
but this is basically patching a bad system architecture.
No one in their right mind would call the 80x86 architecture 'good',
but it offers such a low cost/performance ratio that it is a great
commercial success. It seems that Intel's Itanium processor has failed
to succeed as they hoped due to this effect, the world was not waiting
for Intel to give it a 'good' design, it already had the Sun SPARC, the
IBM PowerPC, and the DEC Alpha (killed off by HP due to the belief the
Itanium would rule it seems?). Ultimately the 80x86 family is a success
as it has a big market share, has benefited from huge investment, and
has kept reverse compatibility with older CPUs to a remarkable degree.
PSC Home Page
Any comments or feedback please make to
psc_AT_sat_DOT_dundee_DOT_ac_DOT_uk which I trust you can work out,
otherwise I'm afraid to have tell you that your grades are insufficient
to pass the Turing Test...
(c) Paul Crawford, 1st Feb 2007