Due to popular request, I extracted the text from the PDF, it's in a gist at the bottom.
A funny (on my account) story:
After three days with little sleep, the last half-day spent finding just one more byte to remove so it fits in a nice rectangle[1], I was finally done. I sent the complete .asm to Oded Margalit, an IBM researcher who organizes the CodeGuru programming competitions in Israel, and he immediately responded "I can shave 5 bytes off".
It turns out instead of the "quit" system call all the books tell you to write:
;;; the program has finished
quit:
mov ah, 04ch ; quit with return code
mov al, 0
int 021h
You can just put a "ret", and DOS loads an address containing these commands to the bottom of your stack so it works.
You had to see my reaction.
[1] it was supposed to be 32x13 characters at the bottom, after it was done I decided to make it 8x52 characters on the right because it looked better. Had I known I would do it, I could've gone to sleep much earlier...
I love it how the OS does the obviously right thing (at least to my eyes, returning from the application's main() function equivalent makes 100% perfect sense), but people who have obviously spent a b*ttload of time with these things are still surprised. Not sure if it's irony, or just tragic. Good story though, thanks!
The first x86 assembly program I wrote ran almost perfectly the first time. That was over 15 years ago and I don't remember what it actually did, but I remember being impressed with myself.
Then the screen filled with junk and my P133 rebooted. When it happened a second time I resigned myself to actually read the assembly manual section about DOS programs properly (i.e. not stop after the part which said .COM files are the simplest way to get started).
The idea of asking the OS to unload my application wasn't obvious to me at all :) At the same time, realising why not asking the OS to unload my application produced the results it did was a lightbulb moment.
It's maybe the right thing, but not the obvious thing.
In the context of DOS assembly language programming, the only obvious thing is "nothing". DOS is barely an OS, it's mostly a library of function calls. DOS does nothing most of the time, so you expect it to do nothing all the time.
At the time I didn't yet spend a lot of time doing DOS assembly language programming, but since then I did, and had I heard about this for the first time today, I would be really surprised.
Due to popular request, I extracted the text from the PDF, it's in a gist at the bottom.
A funny (on my account) story:
After three days with little sleep, the last half-day spent finding just one more byte to remove so it fits in a nice rectangle[1], I was finally done. I sent the complete .asm to Oded Margalit, an IBM researcher who organizes the CodeGuru programming competitions in Israel, and he immediately responded "I can shave 5 bytes off".
It turns out instead of the "quit" system call all the books tell you to write:
You can just put a "ret", and DOS loads an address containing these commands to the bottom of your stack so it works.You had to see my reaction.
[1] it was supposed to be 32x13 characters at the bottom, after it was done I decided to make it 8x52 characters on the right because it looked better. Had I known I would do it, I could've gone to sleep much earlier...