X86 memory segmentation: Difference between revisions

Content deleted Content added
Real mode: OMG, turns out, per en.wikipedia.org/w/index.php?title=X86_memory_segmentation&diff=prev&oldid=441344024 the 1 byte was NOT a typo. So that's where Joh got it from? I CAN actually understand what OR made the OP think 1 byte, but that's not a real (mode) segment size, it's sectionable! Just bc you're not USING all 16 bytes doesn't mean the segment wasn't 16 bytes. If every "1-byte segment" MUST be followed by a 15-byte gap before the next starts, THAT'S ACTUALLY A 16-BYTE SEGMENT!
Real mode: It still wasn't quite clear, I feel. Also, stepping on memory is possible within the same segment (be it the technically maximum size of 64K or smaller) AND by involving any other segment.
Line 35:
Because of the way the segment address and offset are added, a single linear address can be mapped to up to 2<sup>12</sup> = 4096 distinct segment:offset pairs. For example, the linear address 08124h can have the segmented addresses 06EFh:1234h, 0812h:0004h, 0000h:8124h, etc.
 
This could be confusing to programmers accustomed to unique addressing schemes, but it can also be used to advantage, for example when addressing multiple nested data structures. While real mode segments are ''technically'' always 64&nbsp;[[Kilobyte|KB]] long, the practical effect is only that no segment can be ''longer'' than 64&nbsp;KB, rather than that every segment as actually used in a program ''must'' be treated as 64&nbsp;KB long – dealing with effectively smaller segments is possible. Because there is no protection or privilege limitation in real mode, even if a segment is programmatically treated as smaller than 64&nbsp;KB, it is still entirely up to the program to coordinate and keep within the bounds of any segments. This is true both when a segment is programmatically treated as smaller than 64&nbsp;KB, as well as when it is 64&nbsp;KB, but it is also true that any program can always access any memory (by just changing segments, since it can arbitrarily set segment selectors to change segment addresses with absolutely no supervision). Therefore, while real mode can justbe asthought well be imaginedof as having aallowing variabledifferent lengthsegment for each segmentlengths, from 16 through 65,536 bytes (in 16-byte steps), whichand howeveras isallowing justsegments to be overlapping or non-overlapping as desired, none of this is notrestrictively enforced by the CPU.
 
(The leading zeros of the linear address, segmented addresses, and the segment and offset fields are shown here for clarity. They are usually omitted.)