Lost Era – DOSBox, an x86 emulator with DOS – Hello World Assembly COM


The Microsoft DOS (Disk Operating System) has been very popular once (1980s and early 90s) but now it has now completely reached its end. The DOS is an shell-like system that is famous for its prompt C:\.  and if you type anything incorrect, it will complain this by outputting a message: Bad Command or Filename.

At Win9x, (win95 and win98) the DOS kernel (16-bit) is kept for backward compatibility. Thus, the OS runs at a mixed mode of 16 and 32 bit, which yields problems sometimes that are caused by 16-bit programs. Actually, the GUI of Windows at that time is a program that runs above the DOS shell. The OS is not stable. From Win2000 (maybe WinNT), the OS completely rewrites the kernel and abandons DOS. However, in order to run DOS programs, the DOS console (command shell) is introduced, which is a 32-bit emulator that runs 16-bit DOS program but at the meantime supports 32-bit programs as well.

However, at Win7 and Win8, 16-bit DOS programs are abandoned completely, in order to improve the system stability. If you run 16-bit DOS programs, you will have something popped up like below, on Win8 (64-bit):

win8 Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM 16 bit assembly language batch script code debug DOS DOSBOX emulator implementation MSDOS 16-bit programming languages windows windows command shell

This is understandable, but for the programmers like me, I have a very nice memory old times programming DOS programs such as Assembly, playing around 16-bit registers, AX, BX, CX and DX. The debug.exe is considered the most powerful tool under 16-bit DOS at that era. Luckily, there is an opensource project ongoing, The DOSBOX (http://www.dosbox.com) is an x86 emulator with DOS. So you can run your DOS programs without problems in this emulator.

Upon completion of installation, we’ll have a welcome window:

dosbox-welcome Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM 16 bit assembly language batch script code debug DOS DOSBOX emulator implementation MSDOS 16-bit programming languages windows windows command shell

Followed by the Shell prompt (at the start, it is Z:\ which contains some core files of DOS, such as command.com (core kernel), autoexec.bat (batch file that runs automatically when shell is loaded).

dosbox-z Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM 16 bit assembly language batch script code debug DOS DOSBOX emulator implementation MSDOS 16-bit programming languages windows windows command shell

If you type intro that will give you some commonly-used preparation commands to aid you using DOS emulator.

dosbox-mount Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM 16 bit assembly language batch script code debug DOS DOSBOX emulator implementation MSDOS 16-bit programming languages windows windows command shell

The above shows you a useful command that is mount, which can be used to mount a specific directory (your windows system) to a virtual drive (in your DOSBOX emulator).

And it is possible to mount with the CD-ROMs.

dosbox-cdroom Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM 16 bit assembly language batch script code debug DOS DOSBOX emulator implementation MSDOS 16-bit programming languages windows windows command shell

And also, it is provided with some special keys that can speed up things.

dosbox-help Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM 16 bit assembly language batch script code debug DOS DOSBOX emulator implementation MSDOS 16-bit programming languages windows windows command shell

In DOS era, there are three kinds of executables: .BAT (is a plain text file that lists the commands to execute line by line), .COM (binary executable, tiny address space, contains code no larger than 64KB less 256 bytes for PSP Program Segment Prefix, all data and code are together in the same space), and .EXE (similar to what we have on Windows nowadays e.g. Win32 PE Portable Executable).

.COM file executable is a 16-bit binary code that is at most size of 65,280 (FF00h) bytes (256 bytes short of 64 KiB). It doesn’t have a file header. At the beginning, the .COM file will be loaded and instructions will be fetched from the beginning (offset = 0). All data and code share the same memory space.

The Hello World program is simple. We can use the interrupt 09H to print a message, the input string address is specified by DX register. We use INT 21H to call the interrupt (similar as calling sub-procedure). We use INT 20H to return to DOS (terminate the program).

The following simply illustrates the process. Be aware that it is a psudo-code and will be eventually converted slightly. The first line is to fetch the address of the string (msg is the label). It is noted that string should be ended with the dollar sign $ otherwise it will print a mess of craps after the text until reaching one.

mov dx, offset msg
mov ah, 09H
int 21h
int 20h
msg db "Hello, World$"

Using debug.exe will actually print the machine-assembly code line by line.

dosbox-hello Lost Era - DOSBox, an x86 emulator with DOS - Hello World Assembly COM 16 bit assembly language batch script code debug DOS DOSBOX emulator implementation MSDOS 16-bit programming languages windows windows command shell

.COM loads into memory with an offset 0x100H (256 bytes) immediately after PSP (Program Segment Prefix) that is a data structure used in DOS systems to store the state of a program.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
a WordPress rating system
1009 words
Last Post: Frequently Asked Core Java Interview Questions and Answers
Next Post: Lost Era - Microsoft DOS, 16 bit .COM Assembly

The Permanent URL is: Lost Era – DOSBox, an x86 emulator with DOS – Hello World Assembly COM

Leave a Reply