6

We've been asked to write 16-bit assembly code and assemble it to run in DOSBox.

I know that 16-bit assembly code just differs from normal x86 assembly code in that it uses bits 16 and also 16-bit registers (ax, bx ,cx, ...).

I tried searching on how to use NASM for 16-bit code and unfortunately didn't understand what it's saying.

What I just want to know is what parameters to use in NASM to assemble 16-bit assembly code? (-bin or -obj?), and then if possible, how to debug it in Linux. If not possible, how to debug in DOSBox?

Would really like some help here cause we've been given very minimal resources to understand this so I'm really confused.

nrz
  • 10,435
  • 4
  • 39
  • 71
MDuh
  • 415
  • 1
  • 7
  • 19
  • they also differ in some new instructions and addressing modes. In 32 and 64-bit modes most registers can become general purpose – phuclv Mar 08 '14 at 15:13
  • You will probably need a 16 bit tool set. I don't know if there is a NASM based 16 bit tool set. Microsoft later 16 bit tool sets are 32 bit programs using a 32 bit dos extender to run under 16 bit dos, or run natively on 32 bit systems. I don't know what's available for *nix. – rcgldr Mar 08 '14 at 16:00

2 Answers2

5

Depending on what you want to do, creating a com file directly using nasm is a simple option. You should not use any sections, and specify org 100h to compensate for the load address.

Example:

ORG 100h

        lea dx, [msg]
        mov ah,9
        int 21h
        mov ax, 4c00h
        int 21h

msg: DB 'HELLO WORLD$'

Assemble as: nasm -f bin -o test.com test.asm

Dosbox itself has an optional built-in debugger albeit not a very sophisticated one. Could be good enough for your purposes.

Jester
  • 56,577
  • 4
  • 81
  • 125
  • thanks! I will try to use this for my simple asm code. Although I don't think I'll be using this on my longer ones. – MDuh Mar 08 '14 at 16:33
  • You are not supposed to write longer 16 bit dos code anymore :) – Jester Mar 08 '14 at 16:36
  • ok here's my question. Why can't I use sections? [nasm documentation says](http://www.nasm.us/doc/nasmdoc8.html) that you can put .text, .data and .bss – MDuh Mar 08 '14 at 21:24
  • You can use sections. They do NOT go into separate segments. Nasm moves `data` after `.text` and `.bss` after that, but they all go into your one-and-only segment (chosen by DOS). The result is the same as Jester shows. – Frank Kotler Mar 08 '14 at 22:04
1

The best way to create a program for some platform (DOS in this case) is to work on this platform. So, use DOS IDE and DOS debugger running them directly in DosBox.

I don't know whether NASM has DOS version, but you can use FASM for dos.

FASM has very similar syntax to NASM's and if required, later you can convert it easily back to NASM.

FASM has DOS IDE built in, so you don't need to use other. As a debugger you can use FreeDOS debug already installed in DosBox.

johnfound
  • 6,857
  • 4
  • 31
  • 60