How to assemble 16-bit asm code using NASM, then debug it in Linux, before making an executable in DOSBox

StackOverflow https://stackoverflow.com/questions/22270915

Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top