Saturday 14 September 2013

Setting up AFD, NASM and DOSBOX for 8086 assembly ( Step By Step )

1- NASM

Download NASM ( Click on this link ) and install it.

Now open the cmd and change your directory to the installation folder using these instructions
> C:
> cd C:/tutorial/NASM
First instruction is for changing the drive to C if you are in any other drive.
Second instruction is to change current directory to our installation directory. In my case I have installed nasm in "tutorial" folder of C drive.
Now you will have to put all your ASM files in this folder to assemble/compile them .

Alternatively, you can just go to the installation directory through WINDOWS EXPLORER and click/run "nasmpath.bat" file . This will setup path ( skipping everything we discussed above ) and open a new console/cmd/command prompt for you.
Now you can run nasm from anywhere in the cmd. but you will have to be in the directory where your code files are placed.

2- AFD

Now download AFD  and copy it to the installation folder i.e. where your nasm is installed
Open the CMD in the same way ( if you have closed the one we opened earlier ) and enter
> afd

If you don't get an error like the one in the image below then you are good to go. You can stop right here.

But if you get an error ( this is because you have a 64bit OS and afd runs on 32 bit one )  you will have to setup DOSBOX EMULATOR.
So let's continue with installing and configuring DOS box .

3- DOSBOX

First of all create a Separate folder where you will put all the related files ( nasm, afd , code files ).
I have created a folder in C drive and named it "assembly" so my path will become "C:/assembly"

NASM that we downloaded earlier will not work in dosbox. you will have to download it from here ( NASM for DOS ) Download the zip file and extract it somewhere.
Move AFD.exe that we downloaded earlier to the new folder that we created i.e. C:/assembly.Other then that also move nasm.exe and another file cwsdpmi.exe ( from extracted folder ) to our work folder.
Finally, download DOSBOX and install it .

After complete installation , Go to Dosbox installation directory and run "DOSBox 0.74 Options.bat". This will save you from the pain of searching the configuration file yourself and will open that file for you.

Copy these lines at the end of that file.
> MOUNT C 
> C:/assembly
> C:
Replace "C:/assembly" with the path of the folder that you created.
Now you can run dosbox and use nasm and afd.

Remember, 
whenever you add a new file to your work folder ( C:/assembly in my case ) you will have to press CTRL + F4 key so that dosbox update it's directory entries.
You can also enter "intro" command in dosbox for some useful information.

Now to test the environment run dosbox. Enter the following command
> echo mov ax,5 > test.asm
This will create a new file named test.asm and write "mov ax,5" to this file.

Finally, Enter these commands to check if everything is working fine.
> nasm test.asm -o test.com  
> afd test.com
and the following screen should appear

This sums up basic steps of setting up environment for writing and debugging 8086 assembly code.
If you find any thing that I missed and must be added in this article then feel free to comment.

7 comments:

  1. I got error illegal directoriy afd. Whts the problem?

    ReplyDelete
  2. I am unable to download AFD file

    ReplyDelete
  3. how can we get output on black output screen?

    ReplyDelete
  4. You can run AFD.EXE under 64-bit Windows by using Takeda's MS-DOS Player for Win32-x64, see http://takeda-toshiya.my.coocan.jp (run: msdos.exe -cAFD32.EXE AFD.EXE).
    I found AFD.EXE on http://temp.retailsys.bg/, Version 1.00, 1987, works fine.

    ReplyDelete
  5. ILLEGAL COMMAND
    de raha hai nasm se agay dosbox
    afd bhi ILLEGAL COMMAND hi hai
    mount pe already mount hi de raha hai

    ReplyDelete
  6. After echo
    both nasm afd are resulting in ILLEGAL COMMAND.

    ReplyDelete