Program Segment Prefix
Encyclopedia
The Program Segment Prefix (PSP) is a data structure used in DOS
systems to store the state of a program
. It resembles the Zero Page
in the CP/M
operating system. The PSP has the following structure:
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'.
The segment address of the PSP is passed in the DS register when the program is executed. It can also be determined later by using interrupt
21h subfunction 62h. This interrupt will return the PSP address in register BX.
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 displays the command line arguments:
If the command line length is non-zero, programs should first try to retrieve the command line from the appendage of the environment, if the segment pointer to the environment is neither 0000h or FFFFh. This way, it is possible to pass longer command lines than 127 bytes to applications than via the fixed length command line buffer in the PSP. If this appendage is not available (for example under DOS prior to 3.2) or if it turns out to be of length zero, the command line can be retrieved from the PSP itself, but possibly truncated after 127 bytes. Indicated lengths beyond this should not be trusted on.
DOS
DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...
systems to store the state of a program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
. It resembles the Zero Page
Zero page (CP/M)
The Zero Page is a data structure used in CP/M systems for programs to communicate with the operating system. In 8-bit CP/M versions it is located in the first 256 bytes of memory, hence its name....
in the CP/M
CP/M
CP/M was a mass-market operating system created for Intel 8080/85 based microcomputers by Gary Kildall of Digital Research, Inc...
operating system. The PSP has the following structure:
Offset | Size | Contents |
---|---|---|
00h-01h | 2 bytes (code) | CP/M CP/M CP/M was a mass-market operating system created for Intel 8080/85 based microcomputers by Gary Kildall of Digital Research, Inc... exit (always contain INT 20h) |
02h-03h | word (2 bytes) | Memory size in paragraphs |
04h | byte | Reserved |
05h-09h | 5 bytes (code) | Far call to CP/M compatibility code within DOS |
0Ah-0Dh | dword (4 bytes) | Terminate address of previous program (old INT 22h) |
0Eh-11h | dword | Break address of previous program (old INT 23h) |
12h-15h | dword | Critical error address of previous program (old INT 24h) |
16h-17h | word | Caller's PSP segment (usually command.com COMMAND.COM COMMAND.COM is the filename of the default operating system shell for DOS operating systems and the default command line interpreter on Windows 95, Windows 98 and Windows Me... - internal) |
18h-2Bh | 20 bytes | Job File Table Job File Table The Job File Table is a DOS data structure in the Program Segment Prefix . It starts at PSP offset 0x18 and is 20 bytes long. For each open file handle, DOS stores the index into the System File Table... (internal) |
2Ch-2Dh | word | Environment Environment variable Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.They can be said in some sense to create the operating environment in which a process runs... segment |
2Eh-31h | dword | SS:SP on entry to last INT 21h call (Internal) |
32h-33h | word | Max open files (Internal - see below) |
34h-37h | dword | Handle-entries address (Internal - see below) |
38h-4Fh | 24 bytes | Reserved |
50h-52h | 3 bytes (code) | Far call to DOS (always contain INT 21h + RETF) |
53h-5Bh | 9 bytes | Reserved |
5Ch-6Bh | 16 bytes | Unopened Standard FCB File control block A File Control Block is a file system structure in which the state of an open file is maintained.The FCB originates from CP/M and is also present in most variants of DOS... 1 |
6Ch-7Fh | 20 bytes | Unopened Standard FCB 2 (overwritten if FCB 1 is opened) |
80h | 1 byte | Number of bytes on command-line |
81h-FFh | 127 bytes | Command-line (terminated by a 0Dh Carriage return Carriage return, often shortened to return, refers to a control character or mechanism used to start a new line of text.Originally, the term "carriage return" referred to a mechanism or lever on a typewriter... ) |
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'.
The segment address of the PSP is passed in the DS register when the program is executed. It can also be determined later by using interrupt
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
21h subfunction 62h. This interrupt will return the PSP address in register BX.
Alternatively, in .COM
.com
The domain name com is a generic top-level domain in the Domain Name System of the Internet. Its name is derived from commercial, indicating its original intended purpose for domains registered by commercial organizations...
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 displays the command line arguments:
org 100h
int 21h subfunction 9 requires '$' to terminate string
xor bx, bx
mov bl, [80h]
mov byte [bx + 81h], '$'
print the string
mov ah, 9
mov dx, 81h
int 21h
exit
mov ax, 4C00h
int 21h
If the command line length is non-zero, programs should first try to retrieve the command line from the appendage of the environment, if the segment pointer to the environment is neither 0000h or FFFFh. This way, it is possible to pass longer command lines than 127 bytes to applications than via the fixed length command line buffer in the PSP. If this appendage is not available (for example under DOS prior to 3.2) or if it turns out to be of length zero, the command line can be retrieved from the PSP itself, but possibly truncated after 127 bytes. Indicated lengths beyond this should not be trusted on.
External links
- Accessing Command Line Arguments (Microsoft.com)