[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Binary vs ASCII or .EXE vs .COM

rangeela wrote:
> >
> > The difference between .EXE and .COM is that .EXE files are relocatable,
> > i.e. u can load them in any area of memory. The loader takes care of
> converting the address > >references to absolute ones
> The same is true for .com also they can also be located anywhere . The only
> diff . being the one you quoted as follows:
> > Hence .EXE may be
> > larger than 1 DOS segment, i.e. 64 KB. But a .COM is *not* relocatable!
> > The Code, Data and Stack *all* have to be within 1 segment!
> >
> If .com were to be loaded only at a fix position then how come one run
> multiple copy of command.com in DOS.

The x86 architecture has addresses of the form CS:IP, i.e. the address
is formed by the combination of Code Segment (CS) and Instruction
Pointer (IP) registers. In an .EXE, the text, data and stack can span
multiple segemnts, hence jumps may occur over segment boundaries. The
loader ahs to ensure the correct addresses in this case.

In the case of .COM, all jumps, stack operations etc. happen within the
same segment boundary. I was slightly off when I said that a .COM is
*not* relocatable. Well, a .COM is relocatable in the sense that u can
load it in any segemnt, but it can't span segemnt boundaries, all jumps
are local or short jumps and the loader doesn't need to worry much about
patching the addresses. All addresses are in terms of IP only and don't
need to be patched.

I hope the difference is clear now.

BTW, a .COM file contains a 256 byte PSP (Program Segment Prefix) whcih
contains info about the type of file or something, I forgot.

A .EXE contains a "magic string" at the beginning of the file.

Random binary data is identified by the file command as just "data"