[net.micro.pc] Com vs. Exe files

ugthomas@sunybcs.UUCP ( Timothy Thomas) (07/16/85)

This may sound like a stupid question, but what is the difference(s)
between .com and .exe files?   All I know is that when I write a 
turbo pascal program, it is a .com file, and when writing in Lattice
C it comes out to an .exe file.

Could someone please explain to me the difference (and advantages/disad)
of these two types of files?
	Thanx,

-- 

____________   ____/--\____ 
\______  ___) (   _    ____)     "Damn it Jim!,
     __| |____/  / `--'            I'm a programmer not a Doctor!"   
     )           `|=(-
     \------------'
   Timothy D. Thomas                 SUNY/Buffalo Computer Science
   UUCP:  [decvax,dual,rocksanne,watmath,rocksvax]!sunybcs!ugthomas
   CSnet: ugthomas@buffalo,   ARPAnet: ugthomas%buffalo@CSNET-RELAY  

broehl@wateng.UUCP (Bernie Roehl) (07/16/85)

There are a number of differences.

.COM files are smaller, and load slightly faster since they don't require
relocation.  They are essentially memory-image files; they get loaded in
pretty well as-is starting at offset 100h in your program segment.  They
have all four segment registers pointing at the PSP when they start running;
if you don't know what this means, it doesn't really matter.

.EXE files are bigger (they have relocation information in them) and load
a little slower.  They have a header at the start that contains information
about stack space requirements and stuff like that.

.COM files must be position independent.  In other words, they must be able
to execute *anywhere* in memory without change.  .EXE files can be loaded
anywhere, even if they're not position-independent, since the DOS loader
is smart enough to handle the relocation.

The reason Turbo Pascal can produce .COM files is that the code it generates
is position-independent; this is not the case for most other compilers.
(My Turbo Pascal arrived weeks ago, and it's still in the box... I've been
really busy lately).

Speaking of being busy, I've gotta go... hope this helps.

-- 
        -Bernie Roehl    (University of Waterloo)
	...decvax!watmath!wateng!broehl

kimery@wdl1.UUCP (Sam Kimery) (07/19/85)

> This may sound like a stupid question, but what is the difference(s)
> between .com and .exe files?   All I know is that when I write a 
> turbo pascal program, it is a .com file, and when writing in Lattice
> C it comes out to an .exe file.
> 

As far as I remember, com files are relocatable, and contain no
stack.  Just the oposite holds for .exe files


		Sam

johnl@ima.UUCP (07/23/85)

[The question at hand is what the difference is between .COM and .EXE files.]

A .COM file is merely a sequence of bytes.  MS-DOS runs it by loading the
whole thing into memory and starting it at the beginning.  If your program
doesn't fit into one segment, .COM files make life hard for you because there
is no provision for relocating segment numbers within the loaded file to agree
with where the program is actually loaded in memory.  Practically speaking,
this means that .COM programs are limited to 64K of code and 64K of static
data.  (In response to another message, most C compilers are happy to let you
make .COM files of their object code.  I have done it myself with Lattice and
Wizard, and have heard it's easy with most other compilers.)

A .EXE file has a somewhat more complicated format, with a header that tells
how large the code is and how the various segment registers should be set up
when the program starts.  It also has provision for relocating addresses in
the program, which means that the program can be as large as all of memory.

Traditional folklore claimed that .COM files are better than .EXE files,
because they loaded faster or something.  Since DOS 2.1, at least, that
hasn't been true and making your programs into .COM files is of neglible
value.

John Levine, ima!johnl

jim@randvax.UUCP (Jim Gillogly) (07/24/85)

People have been complaining that Lattice C can't produce .COM files.
That's wrong - I use it for .COM files constantly, and have been
for a couple of years.  Simply link the program with CC.OBJ instead of
C.OBJ and ignore the "Missing stack segment" error message from LINK.
It will produce a .EXE file which can then be run through EXE2BIN to
convert it into a .COM file.  No problem.

This is documented in the current version (2.15) of the manual on page 4-15.
I don't know whether it was in earlier versions.  As another correspondent
mentioned, the code+data must be less than 64K together (super-small model?).
-- 
	Jim Gillogly
	{decvax, vortex}!randvax!jim
	jim@rand-unix.arpa