Greetings EveryOne
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:
http://www.drpaulcarter.com/pcasm/. 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
http://forum.nasm.us/index.php?topic=1297.0 in case you need help setting it up.
Next download OpenWatcom compiler from
http://www.openwatcom.org/index.php/Download, 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:
Z:\>mount c "folder path for the hard drive to be mounted at"
For this tutorial we have:
Z:\>mount c /home/(username)/nasm
Next type:
Z:\>c:
Copy "open-watcom-c-dos-1.9.exe" to your mounted hard drive then type:
c:\>open-watcom-c-dos-1.9
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:
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:
http://www.dosbox.com/wiki/MOUNT, and for better understanding of DosBox you can read this:
http://www.dosbox.com/wiki/Drives.
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:
c:\>cd watcom
c:\WATCOM>OWSETENV.BAT
Afterward you can test watcom by typing this:
c:\WATCOM>wcl386
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:
Set PATH=(nasm path);%PATH%
For me nasm lives here: /home/(username)/nasm
so i simply type this:
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):
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:
c:\>nasm -f obj program.asm
Lets assemble "first.asm" and compile link the obj file with watcom:
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:
c:\>watcom-ex>first.exe
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:
; Using Open Watcom
; nasm -f obj prog.asm
; wcl386 prog.obj driver.c asm_io.obj
%include "asm_io.inc"
segment _TEXT public align=1 class=CODE use32
global _asm_main
_asm_main:
enter 0,0 ; setup routine
pusha
mov eax, msg ; print out prompt
call print_string
;call print_nl
popa
mov eax, 0 ; return back to C
leave
ret
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