问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/22270915/how-to-assemble-16-bit-asm-code-using-nasm-then-debug-it-in-linux-before-makin