got some questions about .com and .exe files

Whats the main difference between the two file types?
When two files of the same file name one with .com extension.. the other .exe why does windows give higher priority to the .com file?

help me figure it out pls ;)

Recommended Answers

All 12 Replies

>Whats the main difference between the two file types?
There's a huge difference, not the least of which is complexity. A .com file is nothing more than raw binary that starts at the 256th byte in memory, or 100h. This format is very old (originating from CP/M days, IIRC), and very restricted (it must fit in one 64k segment).

A .exe file is actually a file format called PE (Portable Executable). It consists of headers and segments that hold various chunks of code and other information. A complete description of the PE format is way beyond the scope of a single post, so I'll direct you here. Be sure to visit the external links as they are the real meat of the article. :)

>why does windows give higher priority to the .com file?
It's a holdover from DOS, I imagine.

microsoft's exe's are PE-COFF (correction)

>microsoft's exe's are PE-COFF (correction)
That's not a correction. PE and PE-COFF or PE/COFF are all interchangeable terms.

<<snip>>
A .exe file is actually a file format called PE (Portable Executable).

Not necessarily! ".exe" files were very common under DOS for applications. The ".com" files were mainly used for small utilites and simple commands because they were limited to a small memory footprint . DOS ".exe" files are usually referred to as "MZ" format because they have that character sequence as their identifying signature. There was also a NE (New Executable) format which appeared during the 16-bit Windows and OS/2 days, but is now obsolete. The PE files actually contain a DOS stub as part of the header so that if you try to execute them under DOS, a message will appear telling you why it will not run.[code + data + stack all sharing the same segment]. DOS ".exe" files are usually referred to as "MZ" format because they have that character sequence as their identifying signature. There was also a NE (New Executable) format which appeared during the 16-bit Windows and OS/2 days, but is now obsolete. The PE files actually contain a DOS stub as part of the header so that if you try to execute them under DOS, a message will appear telling you why it will not run.

>microsoft's exe's are PE-COFF (correction)
That's not a correction. PE and PE-COFF or PE/COFF are all interchangeable terms.

The COFF part is most commonly used to talk about the format of the Object File before it is linked into the executable. Under Unix, you have several different Object File Formats (OFF) to choose from -- a.out, COFF, Elf, etc..

http://en.wikipedia.org/wiki/Object_code

The .com was the original executable file type for dos programs. The .com stands for command file. Some of the original dos commands may still be .com files but probably not any more. They probably have all grown too large for that format. The .com is limited to 64k size for everything including data and program. The dot com files (.com) have priority just because they were first.

Com structure :=>

jump here

data1 db ?
data2 db ?
.
.
.
.

here :

call ActualCode
.
.
.
.
call _exit

EXE structure
db 'MZ'
510 byte or more in multiple of 16 :=> MZ header
which contains jump ip,SP,BP,filesize in paragraph,number of relocatable entry, size of that entry etc..

CS:IP where code runs :=>
Actual codes


Another big difference is that total assembly code+ dat size must be <= 64KB.
But the EXE file contains separte segments for data,code,stack,bss,etc.. (data segment,code segment ...) . so the code size is <=64KB, data size is <= 64KB ... .
Again multiple code and data segment can be used to accomodate large program.
So EXE structure is easier to maintain.


But the real advantage of using COM file is the easyness of loading and executing the file. Just copy the code to memory from a even page boundary+100h . and jump to the entry point . Ur prog wil start executing.

But in case of EXE u need to do many steps.

Actual EXE MZ header...

START(hex) OFFSETS(dec) DISCRIPTIONS
00 00 Always 4D 5A. Marks this file as an .EXE file
*02 02 Remainder after dividing load module's size by 512
*04 04 Size of file in 512 byte pages
06 06 Number of relocation table entries
@08 08 Size of header in paragraphs (16 bytes)
0A 10 Minumum number of paragraphs required after loaded program
0C 12 Maximum number of paragraphs required after loaded program
*0E 14 (SS) Offset of Stack Segment in Load module in paragraphs
*10 16 SP regester loaded with this word
12 18 Negative sum (ignore overflow) of all words in file (CRC)
*14 20 IP register loaded with this word
*16 22 (CS) Offset of Code Segment in load module in paragraphs
18 24 Offset of first relocation item.
1A 26 Overlay number. If no overlays used, this is 0

Ahh...yet another discussion concerning the mind-twisting ambiguities of Windows.

ok... thanks guys.... i have figured it out... thanks a lot to all who posted their idea here...(^--^)

The difference is back in the day, .com files made you look hardcore hacker if you wrote them, whereas .exe files made you look like you got a hold of a C++ or QBASIC compiler.

.COM programs are bare binary executables designed to be loaded directly past the
PSP, also referred to as tiny model programs, for the code, data and stack all fit
onto one segment, limiting the programs size.
The .COM format was merely a carry over from CP/M, and so is the PSP, this format
is mainly for small utilities and programs mechanicly translated from CP/M
to DOS.
Old segment 16-bit .EXE programs have been available in very old versions of DOS
, and allow the program's size to be limited to available system memory.
.EXE programs contain allocation information (amount of minimum/maximum memory
to allocate to the program), values to calculate the initial SS : SP and entry point
CS : IP, and relocation information to touch up segment references within the
executable. Not all .EXE programs will allocate all available memory,
.COM programs always have all free memory allocated to them.

The DOS loader does not distinguish .COM's from .EXE's by extension, but
by inspecting the first two bytes of the program file for the ASCII characters
'M' and 'Z'.

Even new 32-bit Portable Executables contain a 16-bit segmented
old executable header which refers to a valid MS-DOS .EXE program
which displays "cannot be run in DOS mode", or such other message.

Many DOS commands are built into the command line interpreter's transient portion
which is freed when programs are loaded and executed.
The search order for executable programs and batch files is, .COM, .EXE, .BAT

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.