0
$\begingroup$

I read that each segment is 64KB,but how? If you have address ABCD:EFGH , then 1 segment is 16B if it is addreses by bytes. How do they don't overlap? Example: 0000:0010 = 00010 0001:0000 = 00010 , is is same address.

$\endgroup$
  • $\begingroup$ I can't understand what you are asking, or why you think a segment is only 16 bytes long. If the address is 16 bits, how many bytes do you think you can address? I don't understand what overlap has to do with it. $\endgroup$ – D.W. Jun 21 '18 at 19:01
  • $\begingroup$ One segment has just 16 distinct addresses,when offset is from 0000-000F segment with offset 0010 overlaps with next segment with offset 0000. $\endgroup$ – user8216974 Jun 21 '18 at 19:05
  • $\begingroup$ by overlap i mean,it has the same logical address $\endgroup$ – user8216974 Jun 21 '18 at 19:06
  • 2
    $\begingroup$ Is this about real-mode segmentation on the x86? $\endgroup$ – harold Jun 21 '18 at 19:13
  • $\begingroup$ x86 where ABCD:EFGH = ABCD0+EFGH, how can cpu differenciate between 0000:0010 and 0001:0000 it points to same 20 bit address,00010 $\endgroup$ – user8216974 Jun 21 '18 at 19:14
2
$\begingroup$

In "real mode" on the x86, an address is 32 bits long. The higher 16 bits can be considered the segment address, while the lower 16 bits are the address within the segment. But it's a bit more complicated than having $2^{16}$ segments of $2^{16}$ addresses each.

If you have a 16-bit address, then you're able to address $2^{16} = 65,536$ different locations. If each of those is a byte, you have 65,536 bytes, or 64KB, of addressable memory. So a segment is at most 64KB long.

To get the actual address, the segment address is effectively shifted left by four bits, then added to the address within the segment. This does, as you've noted, mean that the addresses are not unique! The address 0x0000.00FF is the same as the address 0x000F.000F in this system. Segments can, and frequently do, overlap. And this isn't considered a problem, because in "real mode", there's no protection whatsoever. Segments are just a convenience; the CPU doesn't care if you want to write to opposite ends of memory in completely different segments.

This also limits the total amount of addressable memory to $2^{20}$ bytes, rather than the $2^{32}$ you would expect with an address of that length. But this is also by design: the 8086 has only 20 address pins. So despite the apparent clumsiness of this system, it ended up working out well.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.