Format:DOS COM and PSP
| On this wiki | Facts · Code · Notes · Topics |
|---|
A .COM program is a raw image with no header, loaded at offset 0x100 of its Program Segment Prefix; the 256-byte PSP holds the exit stub, memory top, environment segment, file handle table, FCBs and the command tail at 0x80.
.COM programs
A DOS .COM file has no header or magic: DOS decides by the first two bytes not being MZ or ZM (a .COM that starts with those letters is run as an EXE). The loader allocates a block, builds the PSP at its start and reads the file at PSP:0x100, up to 65535-256 bytes in DOSBox. Execution starts at PSP:0x100, so code is assembled with ORG 100h; CS=DS=ES=SS=the PSP segment and SP is 0xFFFE with a zero word pushed (so a final RET jumps to PSP:0, the INT 20h exit stub).
PSP layout (256 bytes)
As DOSBox-staging models it: 0x00 CD 20 exit; 0x02 word segment of the first byte past the program's memory; 0x04 filler; 0x05 EA far call to the CP/M entry; 0x0A, 0x0E, 0x12 saved INT 22h (terminate), 23h (Ctrl-Break) and 24h (critical error) vectors; 0x16 parent PSP segment; 0x18 file handle table of 20 bytes (0xFF = unused); 0x2C environment segment; 0x2E saved SS:SP; 0x32 maximum number of files (20); 0x34 far pointer to the handle table; 0x38 previous PSP; 0x40 DOS version bytes (DOSBox's own); 0x50 CD 21 CB (INT 21h; RETF); 0x5C first FCB (16 bytes); 0x6C second FCB; 0x80 command tail: a length byte, then up to 126 characters (conventionally starting with a space and ending with CR). Unverified: the field names at 0x3C-0x3F and the meaning of the filler bytes in real MS-DOS.
EXE programs
For MZ executables the PSP is built the same way and the image is loaded at PSP segment + 0x10; see Format:DOS MZ executable for the size, relocation and memory rules.
Code & repositories
- https://github.com/dosbox-staging/dosbox-staging @
e8b4771a7de58a7d5c6d7c9c5b36c6ab09c6d93d· license: GPL-2.0-or-later (declared by the contributor for the files used; GitHub reports BSD-3-Clause AND GPL-2.0-or-later (read from LICENSE; GitHub's API was busy) for the repository)
DOSBox Staging (GPL-2.0-or-later): src/dos/dos_execute.cpp is a compact reference loader for .COM and MZ .EXE files and overlays; src/dos/dos.h and dos_classes.cpp define the PSP.
Tested on: source read, not run: Read dos_execute.cpp, dos.h and dos_classes.cpp at this commit; nothing built or run. · checked 2026-10-19