ArticleslgStudy

computer science

X86 memory models

X86 memory models is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand X86 memory models rather than just read about it. In short: In computing, the x86 memory models are a set of six different memory models of the x86 CPU operating in real mode which control how the segment registers are used and the default size of pointers. Memory segmentation Four registers are used to refer to four segments on the 16-bit x86 segmented memory architecture.

Key takeaways

  • X86 memory models belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect X86 memory models to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of X86 memory models from memory before moving on to harder problems.

Reference excerpt

In computing, the x86 memory models are a set of six different memory models of the x86 CPU operating in real mode which control how the segment registers are used and the default size of pointers.

Memory segmentation

Four registers are used to refer to four segments on the 16-bit x86 segmented memory architecture. DS (data segment), CS (code segment), SS (stack segment), and ES (extra segment). Another 16-bit register can act as an offset into a given segment, and so a logical address on this platform is written segment:offset, typically in hexadecimal notation. In real mode, in order to calculate the physical address of a byte of memory, the hardware shifts the contents of the appropriate segment register 4 bits left (effectively multiplying by 16), and then adds the offset. For example, the logical address 7522:F139 yields the 20-bit physical address:

Note that this process leads to aliasing of memory, such that any given physical address has up to 4096 corresponding logical addresses. This complicates the comparison of pointers to different segments.

Pointer sizes Pointer formats are known as near, far, or huge. These examples each load two adjacent integers into AX and DX from an address stored at [reg].

Near pointers are 16-bit offsets within the reference segment, i.e. DS for data and CS for code. They are the fastest pointers, but are limited to point to 64 KB of memory (to the associated segment of the data type). Near pointers can be held in registers (typically BX, SI, and DI).

Far pointers are 32-bit pointers containing a segment and an offset. To use them the segment register ES is used by using the instruction LES Reg, dword ptr [mem]. They may reference up to 1024 KiB of memory. Note that pointer arithmetic (addition and subtraction) does not modify the segment portion of the pointer, only its offset. Operations which exceed the bounds of zero or 65535 (0xFFFF) will undergo modulo 64K operation just as any normal 16-bit operation. For example, if the segment register is set to 0x5000 and the offset is being incremented, the moment this counter offset becomes (0x10000), the resulting absolute address will roll over to 0x5000:0000.

Huge pointers are essentially far pointers, but are (mostly) normalized every time they are modified so that they have the highest possible segment for that address. This is very slow but allows the pointer to point to multiple segments (i.e. to span more than 64 KB), and allows for accurate pointer comparisons, as if the platform were a flat memory model: It forbids the aliasing of memory as described above, so two huge pointers that reference the same memory location are always equal.

In reality, a compiler may optimize the above Huge pointer code using no branches. This version decrements the segment unconditionally and to compensate, a segment length (0x10) is added to BX. Unlike the previous Huge example, this version does not require the segment:offset to be normalized.

Memory models The memory models are:

Other platforms In protected mode a segment cannot be both writable and executable. Therefore, when implementing the Tiny memory model the code segment register must point to the same physical address and have the same limit as the data segment register. This defeated one of the features of the 80286, which makes sure data segments are never executable and code segments are never writable (which means that self-modifying code is never allowed). However, on the 80386, with its paged memory management unit it is possible to protect individual memory pages against writing. Memory models are not limited to 16-bit programs. It is possible to use segmentation in 32-bit protected mode as well (resulting in 48-bit pointers) and there exist C language compilers which support that. However segmentation in 32-bit mode does not allow to access a larger address space than what a single segment would cover, unless some segments are not always present in memory and the linear address space is just used as a cache over a larger segmented virtual space.

x86-64 On the x86-64 platform, a total of seven memory models exist, as the majority of symbol references are only 32 bits wide, and if the addresses are known at link time (as opposed to position-independent code). This does not affect the pointers used, which are always flat 64-bit pointers, but only how values that have to be accessed via symbols can be placed.

See also Protected mode

Bibliography Turbo C++ Version 3.0 User's Guide. Borland International, Copyright 1992.

References

Worked examples

Example 1 — a first encounter with X86 memory models

Start with the simplest possible case. Write down what X86 memory models claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to X86 memory models before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about X86 memory models ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of X86 memory models

In research
X86 memory models appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses X86 memory models in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
X86 memory models is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer memory, X86 memory management, so understanding it makes those chapters shorter.
In everyday life
Look for X86 memory models outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “X86 memory models” →

How to study X86 memory models in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what X86 memory models means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain X86 memory models out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is X86 memory models in simple terms?

In computing, the x86 memory models are a set of six different memory models of the x86 CPU operating in real mode which control how the segment registers are used and the default size of pointers. Memory segmentation Four registers are used to refer to four segments on the 16-bit x86 segmented mem…

Why does X86 memory models matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study X86 memory models?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on X86 memory models.

Tags

  • Computer memory
  • X86 memory management

Keep exploring