Author Topic: Tutorial: How to run 16-bits NASM on Linux  (Read 13393 times)

Offline Shikatsu

  • Jr. Member
  • *
  • Posts: 10
Tutorial: How to run 16-bits NASM on Linux
« on: February 04, 2012, 09:10:49 PM »
Greetings EveryOne :D

This tutorial will show you How to run 16-bits NASM on Linux.
This method is tested on Ubuntu 11.10 and it may or may not work on other Linux distros.

1) First you need to download and install "DosBox", open Terminal (alt+ctr+t) then type:

Code: [Select]
sudo apt-get install dosbox

2) Next go to this link:
http://www.nasm.us/pub/nasm/releasebuilds/2.09.10/dos/
and download nasm-2.09.10-dos.zip (when this tutorial was created the current version of NASM is 2.09.10).
Now extract the zip file to "/home/(username)/Desktop".
You need "Unrar-free" or "Unrar" for the extraction process.

3) After setting up  "DosBox" and "nasm", open your terminal or your "Dash home" then type: dosbox and hit enter key, voila now you can see the emulated dos command line.

N.B: for your own convenient you might need to change your keyboard layout on dosbox, do to it simple type:

Code: [Select]
keyb "layout"
i.e:
Code: [Select]
keyb fr

4) At this stage you need to mount your hard drive like this:

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

For our tutorial type this:

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

you going to see this line:

Code: [Select]
Drive C is mounted as local directory /home/(username)/Desktop/nasm-2.09.10/

next type:

Code: [Select]
Z:\>c:

Now you can  test if "nasm" is functioning, type:

Code: [Select]
c:\>nasm -h

if you see this: Illegal command: nasm.

it means something is wrong otherwise you will know its working fine.

5) Now we can do some coding, open "gedit" or your favorite editor and copy past this code:

Code: [Select]
segment .text
global start

start:
mov     DL, 'a'
mov     AH, 2h
int     21h

mov     AX, 4C00h
int     21h

save it as "test.asm" at "/home/(username)/Desktop/nasm-2.09.10".

6) Lets assemble our code, go back to "DosBox", and type this:

Code: [Select]
c:\>nasm -f bin test.asm -o test.com

if no error message got printed, it means everything went well.

7) Testing our "com" file, goto "/home/(username)/Desktop/nasm-2.09.10" and see if "test.com" was created, if it's there go back to "DosBox" and type:

Code: [Select]
c:\>test.com

if you see this:

Code: [Select]
c:\>test.com
a
c:\>

I must say congratulation you got 16-bits NASM code to work on Linux.

Enjoy, Shikatsu.
« Last Edit: March 01, 2012, 10:18:06 PM by Shikatsu »

Online Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Tutorial: How to run 16-bits NASM on Linux
« Reply #1 on: February 05, 2012, 12:18:42 AM »
Thanks Shikatsu! A couple of comments...

First, true 16-bit Nasm has been "abandoned" for quite some time. Current "dos" builds are actually 32-bit extended dos. If you actually need Nasm to run in a 16-bit machine (valuable antique!), you'll have to go back to Sourceforge to get it:

http://sourceforge.net/projects/nasm/files/DOS%2016-bit%20binaries%20%28OBSOLETE%29/0.98.39/

Irrelevant here, since Linux wouldn't run on a 16-bit machine anyway...

Second, "global" doesn't mean anything in "-f bin" output mode. I don't know why there isn't a warning about that. A .com file starts at the beginning of your ".text" section, regardless of the "start:" label.

Third, a .com file should really include "org 100h", since that's where dos is going to load us. Since your example doesn't have any memory references, it doesn't matter in this case, but I like to make it a habit to start any .com file with "org 100h" (or 0x100 or 256).

None of these should be considered a "complaint" - I just wanted to clear up a couple details. Thanks again for your contribution!

Best,
Frank


Offline Shikatsu

  • Jr. Member
  • *
  • Posts: 10
Re: Tutorial: How to run 16-bits NASM on Linux
« Reply #2 on: February 06, 2012, 01:29:22 AM »
Thank you very much Mr. Frank Kotler for your reply.

I am completely new to Assembly Language so I still have a lot to study and learn.

When it comes to programming I like to study and learn at a low level that's why I decided to move forward to Assembly from c/c++, java & basic.

I will take the extra miles to learn useless stuff (useless due developments) and even reinvent the wheel if it will grant me the insight look to be a good programmer so I welcome any feedback to help me achieve my goal.

The other day I was experimenting the possibility to run 16-bits NASM code on ubuntu, I tired to search the net for a away but without any luck after hours of trial and error I figured it out on my own, so I decided to share it with everyone and keep a reference in case I forgot how to do it.

Again Thank you Mr. Frank Kotler for your feedback, and I hope I will learn more things from you.

Shikatsu.