Aeon Emulator Blog

October 7, 2009

Segmented Addressing

Filed under: Aeon, x86 Quirks — Greg Divis @ 7:43 am

The first oddity of the x86 instruction set to trip me up was its real-mode addressing. Having done all of my assembly programming in the past in 32-bit protected-mode, I wasn’t really prepared for the weirdness of its segmented addressing. I knew from my past experience running DOS about the 640k of conventional memory, and I had heard about “segments” when writing 16-bit code with pointers, but I didn’t really have a good understanding of what it all meant.

Unfortunately, now I do.

A 16-bit pointer would only allow 65536 possible addresses, and unless you’re on a Commodore 64, that isn’t going to cut it. To extend the range of available addresses, x86 real-mode requires the use of segment registers. It’s a pretty simple concept – you just load a segment register with a base address, and then pointers act as offsets into the selected 64k segment. You might think that this would allow 4 GB of address space, and you would be right if the segments didn’t overlap:

address = (segment * 65536) + offset

Sadly, it isn’t that simple. The actual formula to calculate the physical address in real-mode is:

address = (segment * 16) + offset

This amounts to a grand total of 1 MB of address space. Everything above 640k is reserved (video RAM is also mapped to the area above 640k), leaving the familiar 640k limit for DOS.

If you’ve worked with real-mode before, I’m sure this all seems perfectly obvious, but it hadn’t even occurred to me that it was implemented this way until I did my research.

Let me just say that I’m sure it was much easier for me to emulate this in Aeon that it was for the people that actually wrote code in this environment. I’m glad I missed that period of PC development history.



  1. […] On a normal x86 real-mode PC with a VGA-compatible video card, a 64k region of memory starting at segment 0xA000 is mapped to video RAM. For a DOS application, displaying an image on the screen may or may […]

    Pingback by Emulating VGA « Aeon Emulator Blog — October 23, 2009 @ 2:13 pm

  2. “640k ought to be enough for everybody !”

    Comment by BIllGates — November 25, 2009 @ 3:01 pm

  3. Could you tell me how can I play to Heroes of Might and Magic II to Windows Vista, please? Don´t run with any emulator correctly. Excuse me my english!

    Comment by Jesus — June 9, 2010 @ 1:52 pm

    • Never played it, so I have no idea. You might try installing it in VirtualBox.

      Comment by Greg — June 11, 2010 @ 8:58 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: