The infinitely profitable program

Fred Cisin cisin at xenosoft.com
Sat Jul 2 13:37:04 CDT 2016


On Sat, 2 Jul 2016, Eric Christopherson wrote:
> Genius.
Clever? yes.  Genius? no, or you would have to count too many of us.

> But I would have thought CP/M would at least require a .com file to
> have a header.
> http://peetm.com/blog/?p=55

NO.
A .COM file is a pure image of memory, starting at location 100h.
The "header" or "zero page" or "program segment prefix" is generated on 
the fly during the loading of the program.
(There is a lot more to know about it)

The Zero Page is 256 bytes of data structures.  Among those are a copy of 
the command line (placed at 80h), and, if there was a filename as an 
argument on the command line, a fully parsed File Control Block for that 
filename (placed at location 5Ch)
(There is a lot more to know about it)

The first thing that I did in CP/M was to create a zero length program. 
it seemed intuitively obvious as a needed capability.
Didn't everybody realize that and do it?
It never occurred to me to try to SELL it!  In those days, there was 
almost an assumption that price would be proportional to program length.
For those who wanted "source code" for it:
SAVE 0 A:JMP100.COM
(SAVE was one of the five CP/M internal commands, ERA,REN,DIR,TYPE)

Since program loading created the data structures from 0 through 0FFh, but 
0 bytes did NOT alter the TPA (Transient Program Area), it provided a way 
at the command line to do a jump to location 100h, which could sometimes 
restart or regain control from some kinds of program crashes.


Headers for executable came along with MS-DOS.  (already present in 
many/most operating systems other than CP/M & MS-DOS)
In MS-DOS, a .COM file is STILL a pure image of memory, starting at 
location 100h.
But, an MS-DOS .EXE file is the form of MS-DOS executable that DOES have a 
header.
The .EXE header starts with "MZ".  Having a fixed beginning lets the 
computer recognize which files are .COM and which are .EXE without 
resorting to filename.  'Course that does prevent you from creating a .COM 
file that starts with
DEC BP
POP DX
since that will be indistinguishable from the marker of a .EXE file.

Why "MZ", instead of something else, maybe even something that would NEVER 
be used in a .COM?   Initials of Mark Zbikowski.  Who was he?  As little 
is known about him as is about Howard Fullmer ("Parasitic Engineering" 
and chief engineer for Morrow)

The result is that at the MS-DOS command line, if you type something, the 
command processor (COMMAND.COM) checks its list of internal commands.
If found, it executes it.
If not found, it looks for that a matching filename with .COM, and executes it.
If not found, it looks for .EXE and executes it.
If not found, it looks for .BAT and executes it.
If not found, it gripes.   ("BAD COMMAND OR FILENAME")
(There is a lot more to know about it)

If what was found was .COM or .EXE, then it starts by looking at the first 
two bytes of the file.  It actually DOES NOT MATTER if you rename or 
MIS-name a .COM as .EXE, or MIS-name a .EXE as .COM!  The differentiation 
is done by whether the first two bytes are "MZ".  MIS-naming a .EXE .COM 
will cause it to be found (and run) before one with otherwise same name 
with .EXE extension.  Do you need examples of why you might want to?
(There is a lot more to know about it)

If it is not "MZ", then it creates a program segment prefix, loads the 
file into RAM starting at 100h, and jumps to 100h.
If it IS "MZ", then the .EXE loader processes the header of the file.


.EXE was present in MS-DOS since before release of 1.00, I seriously doubt 
that his earliest ports to MS-DOS were "before the EXE file format 
existed".



--
Grumpy Ol' Fred     		cisin at xenosoft.com


More information about the cctech mailing list