Program Segment Prefix

This is an old revision of this page, as edited by Unschool (talk | contribs) at 03:21, 27 August 2007 (Undid revision 153181667 by Vinnie taylor (talk)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The Program Segment Prefix (PSP) is a data structure used in DOS systems to store the state of a program. It has the following structure:

Offset Size Contents
00-01 Code CP/M exit (always contain INT 20)
02-03 Word Memory size in paragraphs
04 Reserved
05-09 Code Far call to CP/M compatibility code within DOS
0A-0D DWord Terminate address of previous program (old INT 22)
0E-11 DWord Break address of previous program (old INT 23)
12-15 DWord Critical error address of previous program (old INT 24)
16-17 Word Parent psp segment (PSP of caller - usually command.com - internal)
18-2B Bytes Job File Table(JFT) (internal)
2C-2D Word Environment segment
2E-31 DWord SS:SP on entry to last INT 21 call (Internal)
32-33 Word Max open files (Internal - see below)
34-37 DWord Handle-entries address (Internal - see below)
38-4F Reserved
50-52 Code Far call to DOS (always contain INT 21 + RETF)
53-5B Reserved
5C-6B Unopened Standard FCB 1
6C-7F Unopened Standard FCB 2 (overwritten if FCB 1 is opened)
80 Byte Number of characters on command-line
81-FF Bytes Command-line (terminated by a 0Dh)

The PSP is most often used to get the command line arguments of a DOS program, for example the command "foo.exe -a -f" executes foo.exe with the arguments '-a' and '-f'.

Code Samples

The segment address of the PSP can be determined by using interrupt 21 subfunction 62. This interrupt will return the PSP address in register BX.1

Alternatively, in COM programs, one can address the PSP directly just by using the offsets listed above. 00h points to the beginning of the PSP, FFh points to the end, etc. For example, the following code gets the length (in bytes) of the command line arguments:

org 100h
mov al, byte [80h]
; al now contains the number of characters on the command-line (byte 80h of the PSP)

1 http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte8fjk.htm