|
Well, we've covered a first-time production process of making of a .COM file in some detail. But what exactly IS a .COM program? DOS .COM ProgramsThe .COM type of program was the first (and only) type of program that DOS 1.0 understood. It wasn't until DOS 2.0 that a new type of program called a .EXE was invented. DOS 1.0 was a floppy-based system and these floppies didn't hold a lot of data (about 320kbyte), so there was no real worry about very big programs at that point. When DOS 2.0 arrived and supported a hard disk in the IBM PC/XT, there was more memory on a typical PC and the disk space had been expanded to some 10Mbyte and the need for a new type of program had become clearer. In DOS 1.0, a very simple set of rules applied to .COM programs. When a program started, it owned all of the available memory in the computer. If it tried to use more than was present, it wouldn't run right, of course. But there was no memory management in DOS 1.0 and so any program running could simply do whatever it wanted to do, use whatever memory it wanted to use. DOS 1.0 simply kept track of the first available memory location it could use to load up programs. When DOS would run a .COM program, it would simply prepare a special area called the Program Segment Prefix (PSP) in the first 256 bytes of this available memory and then blindly load the entire .COM file starting just after that point. After loading the .COM file (as simple data bytes) into the memory just after the PSP, DOS would set up a few register values, place a return address (to return to DOS) onto the stack, and then jump straight into the program -- always starting that program at the first byte after the PSP. Since 256 bytes corresponds to 0100h in hexadecimal, this is the offset address that was always used. The CS (code segment) register would always point to the beginning of the available memory, though, which was at the beginning of the PSP. When DOS 2.0 arrived, it included memory management features. To remain compatible with DOS 1.0's style of running .COM programs, DOS 2.0 would first allocate the largest available block of memory (often, the only one) and assign it to the .COM program. It would also prepare the first 256 bytes of that block as the PSP and would load the .COM file exactly after that point, quite similarly to DOS 1.0. The main issue with .COM programs running on new versions of DOS is that all of the available memory (or at least, the largest block of memory available) was allocated to the .COM program. So, if the .COM program wanted to avail itself of any of the newer DOS memory management functions to allocate more memory, it usually gets a "no way" response. So, .COM programs will sometimes return all of the unused part of their allocation back to DOS when they first start up. We didn't do that in our early examples, because that process would have greatly complicated my explaining them. The registers that DOS sets up for .COM programs are:
Summary of .COM ProgramsDOS 1.0 only knew how to run .COM programs. In this
first version of DOS, there were also no memory management functions and no concept of
allocated or free blocks of memory. .COM programs were free to use any or all of the
available memory, when they ran. Their stack was simply set up to the end of their program
segment (there was only one such segment) or the end of memory, which ever came first, and
then they were then simply started. DOS just loaded the .COM program into the first
available memory segment and ran them. The .COM file format is really quite simple. DOS doesn't interpret it, it just loads it up into memory and starts it. The first byte in the .COM file is the first byte of the program that starts, when DOS runs it. It's quite a simple process. It's time to talk a little about the Program Segment Prefix (PSP.)
Last updated: Thursday, July 08, 2004 15:02
|