Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Program Segment Prefix
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Data structure in DOS}} {{Use dmy dates|date=May 2019|cs1-dates=y}} {{Use list-defined references|date=December 2021}} {{TOC right}} The '''Program Segment Prefix''' (PSP) is a data structure used in [[DOS]] systems to store the state of a [[computer program|program]]. It resembles the [[Zero page (CP/M)|Zero Page]] in the [[CP/M]] operating system. The PSP has the following structure: {| border="1" width="100%" class="wikitable" ! Offset ! Size ! Contents |- | 00h–01h | 2 bytes (code) | [[CP/M-80]]-like<!-- not CP/M-86! --> exit (always contains [[DOS_API#Interrupt_vectors_used_by_DOS|INT 20h]])<ref name="Taylor_1982_Translators"/><ref name="Paul_2002_COM"/> |- | 02h–03h | [[Word (data type)|word]] (2 bytes) | Segment of the first byte beyond the memory allocated to the program |- | 04h | byte | Reserved |- | 05h–09h | 5 bytes (code) | [[CALL 5 (PSP)|CP/M-80-like]]<!-- not CP/M-86! --> far call entry into DOS, and program segment size<ref name="Taylor_1982_Translators"/><ref name="Necasek_2011_CALL5"/> |- | 0Ah–0Dh | [[dword]] (4 bytes) | Terminate address of previous program (old [[DOS_API#Interrupt_vectors_used_by_DOS|INT 22h]]) |- | 0Eh–11h | dword | Break address of previous program (old [[DOS_API#Interrupt_vectors_used_by_DOS|INT 23h]]) |- | 12h–15h | dword | Critical error address of previous program (old [[DOS_API#Interrupt_vectors_used_by_DOS|INT 24h]]) |- | 16h–17h | word | Parent's PSP segment (usually [[COMMAND.COM]] - internal) |- | 18h–2Bh | 20 bytes | [[Job File Table]] (JFT) (internal) |- | 2Ch–2Dh | word | [[Environment variable|Environment]] segment |- | 2Eh–31h | dword | SS:SP on entry to last [[INT 21h]] call (internal) |- | 32h–33h | word | JFT size (internal) |- | 34h–37h | dword | Pointer to JFT (internal) |- | 38h–3Bh | dword | Pointer to previous PSP (only used by SHARE in DOS 3.3 and later) |- | 3Ch–3Fh | 4 bytes | Reserved |- | 40h–41h | word | DOS version to return (DOS 5 and later, alterable via SETVER in DOS 5 and later) |- | 42h–4Fh | 14 bytes | Reserved |- | 50h–52h | 3 bytes (code) | [[Unix]]-like far call entry into DOS (always contains INT 21h + RETF) |- | 53h–54h | 2 bytes | Reserved |- | 55h–5Bh | 7 bytes | Reserved (can be used to make first FCB into an extended FCB) |- | 5Ch–6Bh | 16 bytes | Unopened Standard [[File control block|FCB]] 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 tail (terminated by a [[Carriage return|0Dh]])<ref name="Paul_1997_MSDOS"/><ref name="Paul_1997_4DOSTIP"/> |} The PSP is most often used to get the [[argc|command line arguments]] of a DOS program; for example, the command "FOO.EXE /A /F" executes FOO.EXE with the arguments '/A' and '/F'. If the PSP entry for the command line length is non-zero and the pointer to the environment segment is neither 0000h nor FFFFh<!-- 0000h indicating "no environment" and "FFFF" reserved -->, programs should first try to retrieve the command line from the [[environment variable]] [[%CMDLINE%]] before extracting it from the PSP. This way, it is possible to pass command lines longer than 126 characters to applications. 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 Int 21h function 51h or Int 21h function 62h. Either function will return the PSP address in register BX.<ref name="R1"/> Alternatively, in [[.COM]] programs loaded at offset <code>100h</code>, one can address the PSP directly just by using the offsets listed above. Offset <code>000h</code> points to the beginning of the PSP, <code>0FFh</code> points to the end, etc. For example, the following code displays the command line arguments: <syntaxhighlight lang="nasm"> org 100h ; .COM - not using ds ; INT 21h subfunction 9 requires '$' to terminate string xor bx,bx mov bl,[80h] cmp bl,7Eh ja exit ; preventing overflow mov byte [bx+81h],'$' ; print the string mov ah,9 mov dx,81h int 21h exit: mov ax,4C00h ; subfunction 4C int 21h </syntaxhighlight> In DOS 1.x, it was necessary for the CS (Code Segment) register to contain the same segment as the PSP at program termination, thus standard programming practice involved saving the DS register (since the DS register is loaded with the PSP segment) along with a zero word to the stack at program start and terminating the program with a RETF instruction, which would pop the saved segment value off the stack and jump to address 0 of the PSP, which contained an INT 20h instruction. <syntaxhighlight lang="nasm"> ; save push ds xor ax,ax push ax ; move to the default data group (@data) mov ax,@data mov ds,ax ; print message in mess1 (21h subfunction 9) mov dx,mess1 mov ah,9 int 21h retf </syntaxhighlight> If the executable was a .COM file, this procedure was unnecessary and the program could be terminated merely with a direct INT 20h instruction or else calling INT 21h function 0. However, the programmer still had to ensure that the CS register contained the segment address of the PSP at program termination. Thus, <syntaxhighlight lang="nasm"> jmp start mess1 db 'Hello world!$' start: mov dx,mess1 mov ah,9 int 21h int 20h </syntaxhighlight> In DOS 2.x and higher, program termination was accomplished instead with INT 21h function 4Ch which did not require the CS register to contain the segment value of the PSP.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)