16-Bit Programs on 64-Bit Systems

Here's a statement you'll hear quite often: "You can't run 16 Bit software on 64 Bit operating systems. It's a limitation of the CPU." Is it true? Well, partially ...

Before we get into the details we'll have to begin with a little history lesson. If you are not interested in that, just scroll to the end. The very first "PC" as we know it today used the Intel 8086 processor. This processor had a single operating mode which was able to access a - back then - enormous address space of 1 MB. Most other systems only had up to 64KB! On the IBM PC this was filled with up to 640KB of RAM, the rest was used for the BIOS, the graphics card, etc. DOS programs run in that mode.
All modern PCs are still able to operate in this mode which was later called "Real mode".

With the introduction of the 80286 processor the chip gained another mode called "Protected mode". It expanded the address space to up to 16 MB and had additional features for multitasking which allowed programs to run simultaneously without interfering with each other. Intel was so excited about this new chip that they didn't even implement a proper way to switch back to Real mode. The idea was that a system would use the "old" Real mode to boot up, switch to Protected mode and never look back ... However the software market doesn't work like that. There was tons of DOS-software which was just plainly incompatible with the new Protected mode. Also it took a while for operating systems to emerge which used all those fancy new features so in fact most people just used an 80286 as a faster 8086, still running plain DOS. Mainboard designers added an ugly hack to switch back to Real mode, it involves the keyboard controller (!) and resetting the whole CPU. Systems like Windows 3.x use Protected mode when run on an 80286 or later CPU.

When the 80386 CPU was released Intel has learned some lessons about software compatibility. They extended the existing Protected mode with 32 Bit features and the addressable memory space expanded to 4 GB. Also they added an easy way back to Real mode. This is not a whole new operating mode, just a new set of features which systems can choose to make use of or not. A flag in a programs code segment indicates whether the code is 16 Bit or 32 Bit. Programs and even the system kernel can mix both modes. For example Windows 3.1 is mostly 16 Bit but has some parts of the kernel, like the disk subsystem, optionally running in 32 Bit. Limited support for 32 Bit applications was introduced with the Win32s extension while still keeping it a 16 Bit system.
But Intel added another thing! The Virtual 86 mode. At this time most software was still DOS based and new systems needed to support that. Virtual 86 mode is called like that because it provides a virtualized 8086 system. A DOS program can get its own address space and doesn't even notice that there are other programs running next to it. If it tries to access the hardware directly, which was quite common, the OS would intercept it and emulate the behavior. Now it was possible to not just run multiple DOS programs at the same time but also run them next to newer 16 or 32 Bit applications. Amazing!

Now lets step more than a decade forward, AMD introduces 64 Bit systems we now use every day. The architecture is called x86_64, x64 or amd64, depending on whom you ask.
The previous paragraphs were all written from my own experience - I've played around quite a bit with the system level stuff, tried writing some simple operating systems using Real mode and Protected mode (16 and 32 Bit). But I haven't had the time to mess around with the new 64 bit mode called "Long mode" at the system level. So from here on I have to rely on things I read on the Internet, please drop me a line if I make a mistake somewhere.

The 64 Bit designs expand the address space again to up to 16 million terabytes, which should be enough for a while. Here I have to insert a little side-rant. Another statement you'll typically hear is: "You can't use more than 4GB of memory with a 32 Bit system." That's just not true. Here's the true version: "You can't use more than 4GB of memory with a 32 Bit typical WINDOWS system.". Try running 32 Bit Linux on a recent machine with more than 4GB of RAM. It will happily make use of all the memory. It's called PAE and available since the Pentium Pro. However a single process can't get more than 4GB so the usefulness is a bit limited ...

64 Bit Long mode cleans up some of the mess left by this evolution of chip designs. Of course the chip designers can't get rid of the old cruft completely because even the newest multicore system still needs to be able to behave like an over 30 year old machine. But in Long mode there is no more segmented memory, no more four-ring model and other things which weren't really used by modern systems anyway. Also Virtual 86 mode was tossed out because the DOS era is long gone now. The new old thing to be supported now, and probably for a long time, is 32 Bit applications. And they will happily run next to 64 Bit programs in long mode because, again, the bittiness is determined by a flag. Interesting enough you can still mark a code segment as 16 Bit and the CPU will execute it in 16 Bit mode. What? Really? YES, IT WORKS!!

Nowadays when people speak of 16 Bit software in the Microsoft world, they really mean two different things: DOS applications (running in Real mode or Virtual 86 mode) and Windows 3.1 applications (running in 16-Bit protected mode). When you try to execute either of those in a 64 Bit Windows system it will tell you that 16 Bit applications are no longer supported. Period. The reason why DOS applications no longer run is clear, no Virtual 86 mode. Windows 3.1 software doesn't run anymore because ... welll .. because Microsoft was lazy. Although they really worked hard on software compatibility. You can still run 20 year old Windows 95 software on todays systems. Do we really need to extend that to 30 years? Other players in the software industry are much worse, Apple, I'm looking at you ...

But how do I run that Windows 3.1 program I can't live without? The answer is a weird one: Just use Linux! There's a software called wine which allows you run a lot of Windows programs on Linux - and unlike Microsoft they didn't toss out 16 Bit compatibility. So on Linux you can really have your 64 Bit system, running 64 Bit Google Chrome to watch a YouTube video, have 32 Bit Skype in the background while playing the classic 16 Bit game Chips Challenge - and everything executes directly on your CPU. Awesome!

For DOS software you have to use a real emulator such as Dosbox which slows down the application your running incredibly. You probably won't notice though, because modern systems are so fast that even then the emulated system will be much faster than any DOS machine back in the day.
If you really want your DOS program running at full 3 GHz+ speeds you can use a virtual machine such as VirtualBox or QEMU. This works because even a virtual machine has to have compatibility all the way back to our current systems ancestor, the 8086.

TL;DR - use Dosbox for DOS software, Use Linux and wine for Windows 3.1 software.

Add new comment