Search code examples
x86segment

Is segment-offset method common to all x86 chips or just 8086?


memory is referred to, using logical address in assembly langugage programming in 8086. is this feature common to all x86 chips including modern pentium microprocessors?


Solution

  • All of the 16- and 32-bit x86 line (8086,8088, 80186, 80286, 80386, i486, Pentium, etc.) use some form of segment/offset addressing. Exactly what the segment refers to, however, changed dramatically from the 8086/88/186 lines to the 80286 onwards lines.

    In the earlier chips, without virtual addressing, the segments referred to the upper 16 bits of a 20-bit memory address while the offset was a 16-bit offset from that. This meant that you had 1MB of directly addressable memory accessed through a set of very heavily-overlapping set of 64KB blocks.

    The later "protected mode" chips switched this around greatly. Instead of a segment being merely the upper 16 bits of a physical address it is instead now an index into one of two lookup tables (the GDT or the LDT) which contain memory structures pointing to the base address, size limits, protection permissions, etc. of the segment. The offset works from that stored base address and is checked against the size limiters to ensure that you don't access memory outside of it, thus ensuring that overlapping addresses, if any, must be explicitly set up to be so instead of the implicit overlapping of the earlier chip sets. The 80286 still had segments limited to 64KB in size, but the 80386 and later got rid of that completely.

    Segments are still used implicitly by the chip. Code is fetched from the CS segment (unless specifically indicated otherwise). Data is fetched from the DS segment (again unless specifically indicated otherwise). The ES is used for the destination in many operations (again unless... you know the drill). The stack is accessed via SS and so on. Many operating systems (perhaps even all?) on the 32-bit processors (post-80286), however, just have all the segments mapping to the same memory space, thus mimicking a flat address space layout. You could likely get away with never thinking about segments at all if you program for Windows NT or later, or if you program for Linux systems or the like.

    The AMD64 instructions are different yet again and are basically a step toward the elimination of segments entirely. It's typically the paging system that's used for protection in that environment.