Another thing, I've been kind of thinking of the int 21h call as a 'do it' operation. Is this the right way to think about the "int 21h" call? I tried googling int 21h to find a clear explination of that operation, but had no luck :/ If so, how does the "int 21h" call know which lines I want it to "do"?
INT is sort of like a CALL instruction that does some extra stuff. Kind of like how CALL is just a JMP that does extra stuff.
Somewhere in memory, there is an "interrupt vector table" (IVT for short) which is just an array of function pointers. The INT instruction looks up an entry in that table (using the numeric operand you gave to INT as the index) and then uses the address in the array to call a function.
Back when I used DOS in real mode, the IVT was at memory address zero.
"But who creates the IVT", you ask? The BIOS does, at system startup. You can read more about the gory details here:
After INT has found the address and called the function, the function itself works just like what Buckeye posted.
Sweet, thank you for the explination and link! gonna read that in a few mins
Looks like most of the important bits were covered, but there are some loose ends.
The first and very important bit is that all of those commands are dead or dying. While Ralph Brown's Interrupt List is useful for hardware developers and for developers in the 1980s and 1990s, today in 2015 it is mostly historical.
That said, if you are doing DOS based programming, that old masm assembler can be a fun way to learn lower level programming. You'll probably need a DOS emulator like dosbox if you want to have most of the old functionality, but I'll assume you've got all that.
Interrupt 21h is the DOS general functionality interrupt.
Hundreds of pieces of DOS functionality were tied into that interrupt. Exactly what functionality took place depends on the contents of the AH register.
01h reads a byte from standard input
02h writes a byte to standard output
09h writes a string to standard output (as you discovered)
2Ah reads the system date
2Bh sets the system date
2Ch reads the system time
2Dh sets the system time
39h creates a disk directory
3Ah deletes a disk directory
3Ch creates a file
3Dh opens a file
3Eh closes a file
And on and on.
There are/were interrupts for every piece of functionality provided by the OS and the hardware. Graphics hardware was generally accessed through interrupt 10h and various ports and memory blocks. The mouse was generally accessed through interrupt 33h.
One of my favorite little bad hacks was to open edlin (a very simple line editor) jump to position 100 (where command executables start) and enter the two bytes cd19. Then save it as a .com file. CD is the bytecode for 'interrupt', I'll let you look up interrupt 19h. Then I'd call the command in their autoexec.bat file, before any TSRs were loaded. Fun times were had by many, but not all.
Anyway, back on track.
Almost every interrupt will expect some values loaded into registers. The system would document those. Back in the 1980s many computers came with manuals that documented all or most of the overriden interrupts and their parameters. Devices like printers and modems would also include details of their command codes and escape sequences. It was cryptic to most people, but necessary for developers and system administrators in order to customize the software and hardware to run together.
You as the programmer could then look up the functionality you needed. If you wanted to change the graphics mode you would set the right parameters to indicate the graphics mode, then call interrupt 10h, and when it returned it would load the status codes. If you wanted to read the mouse coordinates you would set the right parameters to indicate what you wanted to read, and when it returned it would load the mouse position.
As others have pointed out, this is rather dated. Most of these are virtualized on modern hardware, you have your own little sandbox you are playing in and a private little interrupt table is established for your application. Many of the old 16-bit function DOS calls no longer work as Microsoft declared years ago "DOS is dead." But in practice it is not as dead as they had hoped.
Awesome explination and thanks for a short desc of some other interrupt calls, I think I am begining to understand things better! About your cd19 and autoexec.bat hack, did that allow you to control their ROM utilities? haha I looked it up and I read a little about the bootstrap loader.
About this being 16 bit DOS and to learn 32 bit instead, I wish I could because it sounds like its more useful in this day and age, but the reason I am learning it is because it's a required class I need to go toward my CS degree. However my instructor said this semester might be the last semester he teaches this course. All we have done is a "Hello World" application so far, so I am just trying to learn some stuff on my own.
Once again I want to thank everyone for your explinations and help!