PlayOS wrote: In real mode you access a segment by putting it address into a segment register like
mov ax, 0x1000
mov es, ax
this give you access to segment 1 (the second segment out of 16)[...]
Not quite; this is a common misunderstanding, however, so it's no fault of yours. Segmentation is more complex in some ways than it might seem at first (and simpler in some others). I made the same mistake myself, and frankly still have some confusion on the point at times.
It is easy to get the impression that the x86 segmented memory consists of 16 fixed, separate memory areas of 64Kbytes apiece. However, this is not true; a segment is a
potential area of memory, of any size up to 65535 bytes long, which can begin at any location aligned on a 16-byte boundary. Segments may be as small as one byte in size, and two or more segments may overlap each other - or even be exactly the same as each other (this is the case in DOS .com files - all of the segment registers are set to the same base location by DOS before the program is loaded).
The reason for this will become clear if you consider how real-mode addressing works. To get a full-qualified segmented address, you take the segment base, offset by one nibble (4 bits), and add it to the segment offset. Thus, in hex, address 0001:0000 becomes
[tt]
0001 - 16-bit segment base
0000 - 16-bit segment offset
-----
00010 - 20-bit absolute address
[/tt]
This, then, is the 'segment 1' in the sense that you mean (though it is only a segment to the extent that it is used as such by one in an address), but it is not 64Kbytes past origin of segment 0 (0000:0000), but 16 bytes. The two 'segments' overlap each other except at the first and the last 16 bytes. To put it another way, 0001:0000 is the same address as 0000:0010 expressed in two different ways.
This is also the source of the confusion of whether the boot sector is loaded at 0000:7C00 or at 07C0:0000 - both answers are, in fact, equally correct (as are 0001:7BFF and
06C0:1000, but those are less convienent to use). Which you use is a matter of personal choice; so long as you are consistent in how you use it, it will work out either way.
I know this a confusing system, but the Intel designers had there reasons for doing it this way, mostly having to do with hardware constraints that no longer apply. It was as much the cumbersome quality of this segmentation system as the 64K segment size limit that they developed the 32-bit protected mode, with it's then-generous 4G size limit. Now, even that has become a problem for some systems, and 64-bit designs like the Itanium and the Opteron are already in the works (though the Itanium has been stall for many years, and many, including me, feel that it would be best to totally drop the x86 design - which is, in a sense, being emulated rather than run directly on the newer chips anyway - and start from scratch). But I digress...
As I was saying, this particular method of making a 20-bit address out of two 16-bit parts has a number of surprising properties, not the least of which is that it adds up to slightly more than 20 bits - 65420 bytes more, in fact. IF you look at how the numbers add up again, you 'll see that
[tt]
F000
FFFF
------
FFFFF - 1048575 (1Mbyte), the largest possible 20-bit value
whereas,
FFFF
FFFF
------
10FFEF = 1114095 = 1048575 + (65535 - 15)
[/tt]
This extra bit of addressing range is called the High Memory Area, and has been the cause of some serious headaches since the introduction of the 80286 (which had 24 addressing lines instead of 20). When IBM built the AT, they found that even in real mode, you could access those extra 65420 bytes - which was a problem, because some important programs for the PC assumed that the memory would wrap around at FFFFF. To ensure compatibility, IBM set the address decoding up so that the 21st address line (the A20 line) was connected to a previously unused switch in the keyboard controller (an odd approach, to be sure, but it was cheaper than added a new, separate chip). By default, the switch was set to disable the A20 address line, and only by specifically resetting it could the memory 100000 and above be accessed (in either real or 16-bit protected mode). This design has remained enshrined in the design of PCs ever since, which is why you have to do the A20 Line Opening Ritual before accessing extended memory.
HTH. Comments and Corrections Welcome.