Author Topic: Tutorial: How to compile pcasm example codes on DosBox  (Read 16805 times)

Offline Shikatsu

  • Jr. Member
  • *
  • Posts: 10
Tutorial: How to compile pcasm example codes on DosBox
« on: March 02, 2012, 01:49:35 AM »
Greetings EveryOne  ;D

In this Tutorial, I would like to share with you how to compile pcasm example codes on DosBox using OpenWatcom compiler.

Note: This tutorial been tested on on Ubuntu 11.10.

As you might already know Dr. Paul A. Carter have a wonderful book about assembly called: "PC Assembly Language", with example codes which you can download form his website: For this tutorial make sure you download Open Watcom example code.

Make sure you have DosBox on your system, for linux users you can check this tutorial in case you need help setting it up.

Next download OpenWatcom compiler from, choose your convenient server and download "open-watcom-c-dos-1.9.exe" (current version at this time is 1.9).

After you open DosBox, you need to connect physical folders and drives to virtual drives inside DosBox, mount your hard drive like this:

Code: [Select]
Z:\>mount c "folder path for the hard drive to be mounted at"

For this tutorial we have:

Code: [Select]
Z:\>mount c /home/(username)/nasm

Next type:

Code: [Select]

Copy "open-watcom-c-dos-1.9.exe" to your mounted hard drive then type:

Code: [Select]

Follow the instruction and install OpenWatcom, choose full install.

The installation might fail, if it does you might need to set more free space for the mounted drive. In this case close DosBox and open it again. This time you need to mount your drive like this:

Code: [Select]
mount c /home/(username)/nasm -freesize 1024

This will allocate 1Gb of free memory for your mounted drive.

You can learn more about "mount" command from DosBox wiki:, and for better understanding of DosBox you can read this:

I recommend reading the articles in the links above.

Now try to install OpenWatcom with full install, hopefully everything will go smoothly.

With default path, OpenWatcom should be installed in a folder called: "WATCOM" within your mounted drive path.

Before testing OpenWatcom you need to run this batch file: "OWSETENV.BAT", type this:

Code: [Select]
c:\>cd watcom

Afterward you can test watcom by typing this:

Code: [Select]

Now you can tell if your compiler is working or not.

To access nasm from any folder within your mounted drive, you need to set it's PATH. simply type this within dosbox after the drive is mounted:

Code: [Select]
Set PATH=(nasm path);%PATH%

For me nasm lives here: /home/(username)/nasm
so i simply type this:

Code: [Select]
Set PATH=c:;%PATH%

Note that ";%PATH%" helps you keep any path already been set.

After installing DosBox and OpenWatcom, it can be very annoying doing the same thing over and over again when opening DosBox, from mounting the hard drive to running OWSETENV.BAT to setting paths. All this can be done with a simple click by creating a batch file, batch files make life easier indeed.

Lets make a batch file to make our life easier. Open a text editor and type this (i am assuming your are on Linux):

Code: [Select]
dosbox -c "mount c /home/(username)/nasm -freesize 1024 " -c "c:" -c "cls" -c "Set PATH=c:;%PATH%" -c "c:\WATCOM\owsetenv.bat"

Save it as: DosBoxBat.bat (what matters here is the extension .bat)

Note that after running owsetenv.bat from the batch file above every command that comes afterward in DosBoxBat.bat should be added to owsetenv.bat, i add "cls" without quotation marks to the end of owsetenv.bat to have a fresh screen.

Now lets compile an example provided by Dr. Paul A. Carter. After downloading "watcom-ex" and unzipping it, copy "watcom-ex" to your mounted hard drive, double click on DosBoxBat.bat to open DosBox or do it manually.

Since we are going to compile with watcom we need to assemble our assembly code like this:

Code: [Select]
c:\>nasm -f obj program.asm

Lets assemble "first.asm" and compile link the obj file with watcom:

Code: [Select]
c:\>cd watcom-ex
c:\watcom-ex>nasm -f obj first.asm
c:\watcom-ex>wcl386 first.obj driver.c asm_io.obj

Now lets test our output file, type:

Code: [Select]

If everything went smoothly I would like to say congratulation now you know how to to compile Dr. Paul A. Carter's example codes on DosBox ;)

Here is a HelloWorld assembly example:

Code: [Select]
; Using Open Watcom
; nasm -f obj prog.asm
; wcl386 prog.obj driver.c asm_io.obj

%include ""

segment _TEXT public align=1 class=CODE use32
        global  _asm_main
        enter   0,0               ; setup routine

        mov     eax, msg      ; print out prompt
        call    print_string
        ;call    print_nl

        mov     eax, 0            ; return back to C

segment _DATA public align=4 class=DATA use32
msg     DB      "Hello, I am an assembly programmer", 0

Thank you For reading my Tutorial. any question or feedback i would be glad to hear it.

Enjoy, Shikatsu ;D
« Last Edit: March 03, 2012, 01:50:27 AM by Shikatsu »

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Tutorial: How to compile pcasm example codes on DosBox
« Reply #1 on: March 02, 2012, 10:51:18 PM »
Well done, Shikatsu!  8)

Although I personally dread the thought of ever using DOS again I know there are folks out there that need this type of information.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Tutorial: How to compile pcasm example codes on DosBox
« Reply #2 on: March 03, 2012, 12:54:57 AM »
Yeah, thanks Shikatsu!

I remember dos fondly, but when I actually boot to dos (FreeDos), I can't wait to get back to Linux. Fortunately(?) you don't need dos or DosBox to run Dr. Carter's example code. It has versions that'll run on (32-bit extended) dos, Windows, or Linux. I think for 64-bit Linux, you'd need to add "-m32" to gcc's command line to tell it we want 32-bit code, but other than that it should work... (I imagine you'd need a similar trick for 64-bit Windows, but I don't know what the syntax is...)