What is the difference between far pointers and near pointers?

On a 16-bit x86 segmented memory architecture, four registers are used to refer to the respective segments:

  • DS → data segment
  • CS → code segment
  • SS → stack segment
  • ES → extra segment

A logical address on this architecture is written segment:offset. Now to answer the question:

  • Near pointers refer (as an offset) to the current segment.

  • Far pointers use segment info and an offset to point across segments. So, to use them, DS or CS must be changed to the specified value, the memory will be dereferenced and then the original value of DS/CS restored. Note that pointer arithmetic on them doesn’t modify the segment portion of the pointer, so overflowing the offset will just wrap it around.

  • And then there are huge pointers, which are normalized to have the highest possible segment for a given address (contrary to far pointers).

On 32-bit and 64-bit architectures, memory models are using segments differently, or not at all.

Leave a Comment