Program Segment Prefix: Difference between revisions

Content deleted Content added
Undid revision 153181667 by Vinnie taylor (talk)
table, sample
Line 2:
It has the following structure:
 
{| border="1" width="100%" class="wikitable"
|! Offset
|! Size
|! Contents
|-
| 00-01
| 2 bytes (code)
| Code
| [[CP/M]] exit (always contain INT 20)
|-
| 02-03
| [[word (computing)|word]] (2 bytes)
| Word
| Memory size in paragraphs
|-
| 04
| byte
|
| Reserved
|-
| 05-09
| 5 bytes (code)
| Code
| Far call to CP/M compatibility code within DOS
|-
| 0A-0D
| [[DWorddword]] (4 bytes)
| Terminate address of previous program (old INT 22)
|-
| 0E-11
| DWorddword
| Break address of previous program (old INT 23)
|-
| 12-15
| DWorddword
| Critical error address of previous program (old INT 24)
|-
| 16-17
| Wordword
| ParentCaller's pspPSP segment (PSP of caller - usually [[command.com]] - internal)
|-
| 18-2B
| 20 bytes
| Bytes
| [[Job File Table]](JFT) (internal)
|-
| 2C-2D
| Wordword
| [[Environment variable|Environment]] segment
|-
| 2E-31
| DWorddword
| SS:SP on entry to last INT 21 call (Internal)
|-
| 32-33
| Wordword
| Max open files (Internal - see below)
|-
| 34-37
| DWorddword
| Handle-entries address (Internal - see below)
|-
| 38-4F
| 24 bytes
|
| Reserved
|-
| 50-52
| 3 bytes (code)
| Code
| Far call to DOS (always contain INT 21 + RETF)
|-
| 53-5B
| 9 bytes
|
| Reserved
|-
| 5C-6B
| 16 bytes
|
| Unopened Standard [[File control block|FCB]] 1
|-
| 6C-7F
| 20 bytes
|
| Unopened Standard FCB 2 (overwritten if FCB 1 is opened)
|-
| 80
| Byte1 byte
| Number of characters on command-line
|-
| 81-FF
| 127 bytes
| Bytes
| Command-line (terminated by a [[Carriage_return|0Dh]])
|}
Line 90:
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 can be determined by using [[interrupt]] 21 subfunction 62. This interrupt will return the PSP address in register BX.<supref>1http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte8fjk.htm</supref>
==Code Samples==
 
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) ofdisplays the command line arguments:
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.<sup>1</sup>
 
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:
 
<pre><nowiki>
org 100h
 
mov al, byte [80h]
; int 21h subfunction 9 requires '$' to terminate string
; al now contains the number of characters on the command-line (byte 80h of the PSP)
xor bx, bx
mov al, byte bl, [80h]
mov byte [81h+bx], '$'
 
; print the string
mov ah, 9
mov dx, 81h
int 21h
 
; exit
mov ax, 4C00h
int 21h
</nowiki></pre>
 
== References ==
<sup>1</sup> http://www.htl-steyr.ac.at/~morg/pcinfo/hardware/interrupts/inte8fjk.htm
{{reflist}}
 
[[Category:DOS on IBM PC compatibles]]