From OSDev Wiki
Jump to: navigation, search
Executable Formats

16 bit:
32/64 bit:
Mixed (16/32 bit):


The MS-DOS EXE format, also known as MZ after its signature (the initials of Microsoft engineer Mark Zbykowski), was introduced with MS-DOS 2.0 (version 1.0 only sported the simple COM format). It is designed as a relocatable executable running under real mode. As such, only DOS and Windows 9x can use this format natively, but there are several free DOS emulators (e.g., DOSBox) that support it and that run under various operating systems (e.g., Linux, Amiga, Windows NT, etc.). Although they can exist on their own, MZ executables are embedded in all NE, LE, and PE executables, usually as stubs so that when they are ran under DOS, they display:

   This program cannot be run in MS-DOS mode.

However, they can also be used so that a single executable can provide 2 ports of the same application (e.g.,one for DOS and one for Windows). Windows 9x will run the MZ executable if the program is started from the command line prompt, or the PE executable if started normally. In the case of boot loaders, they can help provide a DOS version, esp. since (U)EFI requires the PE format which contains a MZ executable.

MZ File Structure

MZ executables only consists of 2 structures: the header and the relocation table. The header, which is followed by the program image, looks like this:

Offset Field Size Description
0 Signature word 0x5A4D (ASCII for 'M' and 'Z')
2 Extra bytes word Number of bytes in the last page.
4 Pages word Number of whole/partial pages.
6 Relocation items word Number of entries in the relocation table.
8 Header size word The number of paragraphs taken up by the header.
10 Minimum allocation word The number of paragraphs required by the program, excluding the PSP and program image. If no free block is big enough, the loading stops.
12 Maximum allocation word The number of paragraphs requested by the program. If no free block is big enough, the biggest one possible is allocated.
14 Initial SS word Relocatable segment address for SS.
16 Initial SP word Initial value for SP.
18 Checksum word When added to the sum of all other words in the file, the result should be zero.
20 Initial IP word Initial value for IP.
22 Initial CS word Relocatable segment address for CS.
24 Relocation table word The (absolute) offset to the relocation table.
26 Overlay word Value used for overlay management. If zero, this is the main executable.
28 Overlay information N/A Files sometimes contain extra information for the main's program overlay management.

Note: A paragraph is 16 bytes in size.

Each pointer in the relocation table looks as such:

Field Size (in bytes)
Offset 2
Segment 2

If both the minimum and maximum allocation fields are cleared, MS-DOS will attempt to load the executable as high as possible in memory. Otherwise, the image will be loaded just above the 256-byte PSP structure, in low memory.

See Also

Personal tools