Microsoft type executable files

Brian23

Banned
Dec 28, 1999
1,655
1
0
Does anyone remember .com files? I can't remember the last time I ran an executable that was a .com file. What are the advantages of *.exe over *.com? I know that EXE files have some kind of data table at the begining that com files lack, but otherwise they should be able to do the same thing. Why did the com file die?
 

CrispyFried

Golden Member
May 3, 2005
1,122
0
0
coms were limited in size (64k?) and all code and data had to load in a continious memory block. They were very easy for the os to load, just copy the file right to memory. Its basically a straight image of what goes into memory. exes can be most any size and different parts of it can load in different blocks of memory. They are harder to load as they need to be pulled apart and sorted out, then loaded.

 

itachi

Senior member
Aug 17, 2004
390
0
0
i don't know if you could dynamically link code or not, but if you can.. whatever benefits you may receive from doing that will be sht compared to the slow down caused by the flat model. like cripsyfried said.. coms are limited to 64 kb, but it can't be anywhere. it has to be loaded into the first 64 kb of the real mode memory.. so you're stuck with loading code into that segment, which you don't even have real access to.. (windows 2000/xp both run in protected mode, the real mode flat model is emulated). when you run in real-mode.. you can only use 16-bit registers.. so all u got is ax, bx, cx, dx.. no fpu/mmx/sse instructions or use of extended registers (eax, ebx, ecx, edx, ebp, esp, etc..).
little fact.. when you run in protected mode, the 64 kb block of memory is used as segment registers for addressing the flat segment of a program in virtual memory. which basically allows you to address as if you had the full 4 gb of memory to yourself (for 32-bit os's) and more importantly.. it lets you multitask. running in real mode, the os can't switch between 1 program and another until the first one finishes execution.
 

Calin

Diamond Member
Apr 9, 2001
3,112
0
0
The .com file model has a single 64kB segment (16 bit memory space). If you need to use more than those 64kB, you're out of luck.
An DOS mode .exe program, on the other hand, can have several segments of different kinds (data, code, stack). The only reason to use a .com program was low overhead at startup and very low use of memory. However, if you needed one byte over the 64kB limit, there was no easy way to access it. Some TSR (Terminate and stay resident) programs were written as .com files to limit the memory they use (think of mouse drivers, but not only). Also, command.com
In Windows 98 versions (and maybe in Windows 95 also) the command.com file was like 95 kB in size. The .com model was somewhat changed, I suppose
 

cquark

Golden Member
Apr 4, 2004
1,741
0
0
Actually, the old .EXE format is dead too. It's often called the MZ format for the magic number which identified MS DOS EXE's in their header. EXEs were very simple: just a short header, relocation table, and binary image. It was replaced by the NE (New Executable) format in the Windows 3.x series systems, but that's now obsolete too.

Modern Win32 systems use the PE (portable executable) format, and modern Win64 systems use a 64-bit version of that format. PEs contain a DOS stub in EXE format in case someone executes them in a DOS environment, which generally just displays a message like "This program requires Windows." PE files may have a .EXE suffix, but they can also have DLL, SCR, SYS, and other suffixes, depending on their use.

The reasons for the change are basically due to changes in memory management from MS-DOS to MS Windows NT. MS-DOS offered no memory protection and dealt with memory in terms of large segments, while MS Windows NT and its descendents like XP offer true virtual memory with memory protection and deal with memory in terms of pages, which can be scattered across physical memory or even written to the disk. They also have to deal with shared libraries, which can be shared between multiple processes and loaded at a different memory location each time, so relocation is a more complex issue in modern Windows systems.
 

Marthisdil

Senior member
Aug 13, 2001
443
0
71
In DOS, if you had 2 files with the same name, but one was COM and the other EXE, DOS would execute the COM one first.
 

itachi

Senior member
Aug 17, 2004
390
0
0
nah.. com and exe extensions precede bat by default, unless u change the order through doskey for later versions of dos or autoexec.bat for older versions.
 

CrispyFried

Golden Member
May 3, 2005
1,122
0
0
Oops youre right, .bats are last. Makes sense from a security standpoint. I do remember always putting the \bat dir 1st in the path statement back in the day, maybe thats why I thought that. Or it maybe was the droogz :p
 

imported_BikeDude

Senior member
May 12, 2004
357
1
0
Just some minor nitpicking...:

Originally posted by: Calin
The .com file model has a single 64kB segment (16 bit memory space). If you need to use more than those 64kB, you're out of luck.

I'd like to point out that the segment size is 64KB. We're not talking a metric kilo here, but rather 1024 Bytes. ;) (although I've forgotten whether the 16 Bytes which prefaces the segment is part of the segment itself or not)

Incidentally, EXE files didn't appear until later DOS versions (2.0?) -- in any case COM was the only way to go for a while.

In Windows 98 versions (and maybe in Windows 95 also) the command.com file was like 95 kB in size. The .com model was somewhat changed, I suppose

Well, it could've been a EXE file masquerading as a COM file. The loader didn't really care about the extension much IIRC. (the command.com that comes with Win2003 Server OTOH is a mere 50K and doesn't have the MZ header)

Originally posted by: cquark
PE files may have a .EXE suffix, but they can also have DLL, SCR, SYS, and other suffixes, depending on their use.

I'm pretty sure you could rename a PE file to .shrubbery and pass that filename to the CreateProcess() function. The extension helps the shell (and the associated Shell API) and the user, but not the core API.

 

Calin

Diamond Member
Apr 9, 2001
3,112
0
0
Yes, we are talking about 65536 bytes in a 64KB segment. Unlike the .com files (which were able to access a single 64kB segment), the .exe files of the 8086 and 286 era were able to access several 64kB segment.
I would understand that in DOS 1.0 only the .com model of exe existed - remember that the operating system DOS was to replace (the CP/M) had similar restrictions, and most programs didn't use much more memory than this.

Calin