So i was wondering if there is any? I know afd on windows but not sure anything about mac?
And this his how i am using nasam on the following code: nasm a.asm -o a.com -l a.lst
[org 0x100]
mov ax, 5
mov bx, 10
add ax, bx
mov bx, 15
add ax, bx
mov ax, 0x4c00
int 0x21
On windows i know a debugger name afd which help me to step through each statement but not sure how i can do this using gdb.
And neither i am able to execute this .com file, am i supposed to make some other file here?
Why are you writing 16-bit code that makes DOS syscalls? If you want to know how to write asm that’s applicable to your OS, take a look the code generated by “
gcc -S” on some C code… (Note that code generated this way will have operands reversed, and is meant to be assembled withasinstead ofnasm)Further, are you aware what this code is doing? It reads to me like this:
Seems like this code is equivalent to:
Which according to what I see here, is
exit(0). You didn’t need to changebxeither…But. This doesn’t even apply to what you were trying to do, because Mac OS X is not MS-DOS, does not know about DOS APIs, cannot run
.COMfiles, etc. I wasn’t even aware that it can run 16 bit code. You will want to look at nasm’s-f elfoption, and you will want to use registers likeeaxrather thanax.I’ve not done assembly programming on OS X, but you could theoretically do something like this:
Then:
Of course this is relying on the C library, which you might not want to do. I’ve omitted the “full” version because I don’t know what the syscall interface looks like on Mac. On many platforms your entry point is the symbol
_startand you do syscalls withint 80horsysenter.As for debugging… I would also suggest GDB. You can advance by a single instruction with
stepi, and theinfo registerscommand will dump register state. Thedisassemblecommand is also helpful.Update: Just remembered, I don’t think Mac OS X uses ELF… Well.. Much of what I wrote still applies. 🙂