<s>
In	O
computing	O
,	O
the	O
x86	B-Device
memory	I-Device
models	I-Device
are	O
a	O
set	O
of	O
six	O
different	O
memory	O
models	O
of	O
the	O
x86	B-Operating_System
CPU	O
operating	O
in	O
real	B-Application
mode	I-Application
which	O
control	O
how	O
the	O
segment	B-General_Concept
registers	I-General_Concept
are	O
used	O
and	O
the	O
default	O
size	O
of	O
pointers	O
.	O
</s>
<s>
Four	O
registers	B-General_Concept
are	O
used	O
to	O
refer	O
to	O
four	O
segments	O
on	O
the	O
16-bit	O
x86	B-Operating_System
segmented	B-General_Concept
memory	I-General_Concept
architecture	O
.	O
</s>
<s>
DS	O
(	O
data	B-General_Concept
segment	B-General_Concept
)	O
,	O
CS	O
(	O
code	B-Language
segment	B-General_Concept
)	O
,	O
SS	O
(	O
stack	B-General_Concept
segment	B-General_Concept
)	O
,	O
and	O
ES	O
(	O
extra	O
segment	B-General_Concept
)	O
.	O
</s>
<s>
Another	O
16-bit	O
register	O
can	O
act	O
as	O
an	O
offset	O
into	O
a	O
given	O
segment	B-General_Concept
,	O
and	O
so	O
a	O
logical	O
address	O
on	O
this	O
platform	O
is	O
written	O
segment:offset	B-General_Concept
,	O
typically	O
in	O
hexadecimal	O
notation	O
.	O
</s>
<s>
In	O
real	B-Application
mode	I-Application
,	O
in	O
order	O
to	O
calculate	O
the	O
physical	O
address	O
of	O
a	O
byte	O
of	O
memory	O
,	O
the	O
hardware	O
shifts	O
the	O
contents	O
of	O
the	O
appropriate	O
segment	B-General_Concept
register	I-General_Concept
4bits	O
left	O
(	O
effectively	O
multiplying	O
by	O
16	O
)	O
,	O
and	O
then	O
adds	O
the	O
offset	O
.	O
</s>
<s>
Note	O
that	O
this	O
process	O
leads	O
to	O
aliasing	B-Application
of	O
memory	O
,	O
such	O
that	O
any	O
given	O
physical	O
address	O
has	O
up	O
to	O
4096	O
corresponding	O
logical	O
addresses	O
.	O
</s>
<s>
Near	O
pointers	O
are	O
16-bit	O
offsets	O
within	O
the	O
reference	O
segment	B-General_Concept
,	O
i.e.	O
</s>
<s>
DS	O
for	O
data	B-General_Concept
and	O
CS	O
for	O
code	B-Language
.	O
</s>
<s>
They	O
are	O
the	O
fastest	O
pointers	O
,	O
but	O
are	O
limited	O
to	O
point	O
to	O
64KB	O
of	O
memory	O
(	O
to	O
the	O
associated	O
segment	B-General_Concept
of	O
the	O
data	B-General_Concept
type	O
)	O
.	O
</s>
<s>
Near	O
pointers	O
can	O
be	O
held	O
in	O
registers	B-General_Concept
(	O
typically	O
SI	O
and	O
DI	O
)	O
.	O
</s>
<s>
Far	B-General_Concept
pointers	I-General_Concept
are	O
32-bit	O
pointers	O
containing	O
a	O
segment	B-General_Concept
and	O
an	O
offset	O
.	O
</s>
<s>
To	O
use	O
them	O
the	O
segment	B-General_Concept
register	I-General_Concept
ES	O
is	O
used	O
by	O
using	O
the	O
instruction	O
les	O
[reg]|[mem],dword	O
 [ mem ] | [ reg ] 	O
.	O
</s>
<s>
Note	O
that	O
pointer	O
arithmetic	O
(	O
addition	O
and	O
subtraction	O
)	O
does	O
not	O
modify	O
the	O
segment	B-General_Concept
portion	O
of	O
the	O
pointer	O
,	O
only	O
its	O
offset	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
segment	B-General_Concept
register	I-General_Concept
is	O
set	O
to	O
0x5000	O
and	O
the	O
offset	O
is	O
being	O
incremented	O
,	O
the	O
moment	O
this	O
counter	O
offset	O
becomes	O
(	O
0x10000	O
)	O
,	O
the	O
resulting	O
absolute	O
address	O
will	O
roll	O
over	O
to	O
0x5000:0000	O
.	O
</s>
<s>
Huge	O
pointers	O
are	O
essentially	O
far	B-General_Concept
pointers	I-General_Concept
,	O
but	O
are	O
(	O
mostly	O
)	O
normalized	O
every	O
time	O
they	O
are	O
modified	O
so	O
that	O
they	O
have	O
the	O
highest	O
possible	O
segment	B-General_Concept
for	O
that	O
address	O
.	O
</s>
<s>
This	O
is	O
very	O
slow	O
but	O
allows	O
the	O
pointer	O
to	O
point	O
to	O
multiple	O
segments	O
,	O
and	O
allows	O
for	O
accurate	O
pointer	O
comparisons	O
,	O
as	O
if	O
the	O
platform	O
were	O
a	O
flat	B-General_Concept
memory	I-General_Concept
model	I-General_Concept
:	O
It	O
forbids	O
the	O
aliasing	B-Application
of	O
memory	O
as	O
described	O
above	O
,	O
so	O
two	O
huge	O
pointers	O
that	O
reference	O
the	O
same	O
memory	O
location	O
are	O
always	O
equal	O
.	O
</s>
<s>
In	O
protected	B-Application
mode	I-Application
a	O
segment	B-General_Concept
cannot	O
be	O
both	O
writable	O
and	O
executable	O
.	O
</s>
<s>
Therefore	O
,	O
when	O
implementing	O
the	O
Tiny	O
memory	O
model	O
the	O
code	B-Language
segment	B-General_Concept
register	I-General_Concept
must	O
point	O
to	O
the	O
same	O
physical	O
address	O
and	O
have	O
the	O
same	O
limit	O
as	O
the	O
data	B-General_Concept
segment	B-General_Concept
register	I-General_Concept
.	O
</s>
<s>
This	O
defeated	O
one	O
of	O
the	O
features	O
of	O
the	O
80286	B-General_Concept
,	O
which	O
makes	O
sure	O
data	B-General_Concept
segments	O
are	O
never	O
executable	O
and	O
code	B-General_Concept
segments	I-General_Concept
are	O
never	O
writable	O
(	O
which	O
means	O
that	O
self-modifying	B-Application
code	I-Application
is	O
never	O
allowed	O
)	O
.	O
</s>
<s>
However	O
,	O
on	O
the	O
80386	O
,	O
with	O
its	O
paged	B-General_Concept
memory	I-General_Concept
management	I-General_Concept
unit	I-General_Concept
it	O
is	O
possible	O
to	O
protect	O
individual	O
memory	O
pages	O
against	O
writing	O
.	O
</s>
<s>
It	O
is	O
possible	O
to	O
use	O
segmentation	B-General_Concept
in	O
32-bit	O
protected	B-Application
mode	I-Application
as	O
well	O
(	O
resulting	O
in	O
48-bit	O
pointers	O
)	O
and	O
there	O
exist	O
C	O
language	O
compilers	O
which	O
support	O
that	O
.	O
</s>
<s>
However	O
segmentation	B-General_Concept
in	O
32-bit	O
mode	O
does	O
not	O
allow	O
to	O
access	O
a	O
larger	O
address	O
space	O
than	O
what	O
a	O
single	O
segment	B-General_Concept
would	O
cover	O
,	O
unless	O
some	O
segments	O
are	O
not	O
always	O
present	O
in	O
memory	O
and	O
the	O
linear	B-General_Concept
address	I-General_Concept
space	I-General_Concept
is	O
just	O
used	O
as	O
a	O
cache	O
over	O
a	O
larger	O
segmented	O
virtual	O
space	O
.	O
</s>
<s>
Technically	O
,	O
the	O
"	O
flat	O
"	O
32-bit	O
address	O
space	O
is	O
a	O
"	O
tiny	O
"	O
memory	O
model	O
for	O
the	O
segmented	B-General_Concept
address	I-General_Concept
space	I-General_Concept
.	O
</s>
<s>
Under	O
both	O
reigns	O
all	O
four	O
segment	B-General_Concept
registers	I-General_Concept
contain	O
one	O
and	O
the	O
same	O
value	O
.	O
</s>
<s>
On	O
the	O
x86-64	B-Device
platform	O
,	O
a	O
total	O
of	O
seven	O
memory	O
models	O
exist	O
,	O
as	O
the	O
majority	O
of	O
symbol	O
references	O
are	O
only	O
32	O
bits	O
wide	O
,	O
and	O
if	O
the	O
addresses	O
are	O
known	O
at	O
link	O
time	O
(	O
as	O
opposed	O
to	O
position-independent	B-Operating_System
code	I-Operating_System
)	O
.	O
</s>
