HOME

TheInfoList



OR:

The Program Segment Prefix (PSP) is a data structure used in
DOS DOS is shorthand for the MS-DOS and IBM PC DOS family of operating systems. DOS may also refer to: Computing * Data over signalling (DoS), multiplexing data onto a signalling channel * Denial-of-service attack (DoS), an attack on a communicat ...
systems to store the state of a
program Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * Program, a part of planning Arts and entertainment Audio * Progra ...
. It resembles the
Zero Page The zero page or base page is the block of memory at the very beginning of a computer's address space; that is, the page whose starting address is zero. The size of a page depends on the context, and the significance of zero page memory versus h ...
in the
CP/M CP/M, originally standing for Control Program/Monitor and later Control Program for Microcomputers, is a mass-market operating system created in 1974 for Intel 8080/ 85-based microcomputers by Gary Kildall of Digital Research, Inc. Initial ...
operating system. The PSP has the following structure: The PSP is most often used to get the
command line arguments A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
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, programs should first try to retrieve the command line from the
environment variable An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. For example, a running process can query the value of the TEMP env ...
%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. Alternatively, in
.COM The domain name .com is a top-level domain (TLD) in the Domain Name System (DNS) of the Internet. Added at the beginning of 1985, its name is derived from the word ''commercial'', indicating its original intended purpose for domains registere ...
programs loaded at offset 100h, one can address the PSP directly just by using the offsets listed above. Offset 000h points to the beginning of the PSP, 0FFh points to the end, etc. For example, the following code displays the command line arguments: org 100h ; .COM - not using ds ; INT 21h subfunction 9 requires '$' to terminate string xor bx,bx mov bl, 0hcmp bl,7Eh ja exit ; preventing overflow mov byte
x+81h X, or x, is the twenty-fourth and third-to-last letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''"ex"'' (pronounced ), ...
'$' ; print the string mov ah,9 mov dx,81h int 21h exit: mov ax,4C00h ; subfunction 4C int 21h
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 to the stack at program start (since the DS register is loaded with the PSP segment) 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. ; 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 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, jmp start mess1 db 'Hello world!$' start: mov dx,mess1 mov ah,9 int 21h int 20h 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.


See also

* Zero page (CP/M) * CALL 5 (DOS) *
Stack frame In computer science, a call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, program stack, control stack, run-time stack, or mac ...
(Unix) * Process directory (Multics) *
Process identifier In computing, the process identifier (a.k.a. process ID or PID) is a number used by most operating system kernels—such as those of Unix, macOS and Windows—to uniquely identify an active process. This number may be used as a parameter in various ...
(PID) *
this (computer programming) this, self, and Me are keywords used in some computer programming languages to refer to the object, class, or other entity of which the currently running code is a part. The entity referred to by these keywords thus depends on the execution con ...
*
Self-reference Self-reference occurs in natural or formal languages when a sentence, idea or formula refers to itself. The reference may be expressed either directly—through some intermediate sentence or formula—or by means of some encoding. In philoso ...


References


Further reading

* (41 pages) * * {{cite book , title=DOS 5 für Programmierer: Die endgültige Referenz , language=de , chapter=Kapitel 5: EXEC im Detail - Program Segment Prefix (PSP) , author-first=Arne , author-last=Schäpers , date=1991 , edition=1 , publisher= Addison Wesley (Deutschland) GmbH , isbn=3-89319-350-2 , pages=148–151, 971–972 (1123+v pages, foldout, 5.25"-floppy)


External links


Accessing Command Line Arguments
(Microsoft.com) DOS technology