UMBC CMSC 211

UMBC | CSEE


Program Segment Prefix (PSP)

There is a 256 byte segment attached by DOS to the beginning of all programs, and while much of it is no longer used, there are a couple of interesting items still in it:
Offset Meaning
0h INT 20h (old-style return to DOS instruction
2h segment of first paragraph above this program's allocation
2ch segment containing environment variables for this program
32h maximum number or open files for this program
80h number of bytes in command line, excluding command and terminating carriage return
80h-0ffhthe command tail
If we type in the command line: DOIT par1 par2 The last part of the PSP would be:
0Ah ' ' 'P' 'a' 'r' '1' ' ' 'P' 'a' 'r' '2' 13  
(When the command comes from the keyboard, the carriage return is there, but there is nothing to ensure that it will be there if another program starts this on.) Let's look at a program using the PSP.

INCLUDE PCMAC.INC    
  .MODEL SMALL  
  ASSUME NOTHING ; When using multiple data segments,
; this is keeps this correct.
  .STACK 100h  
PSP SEGMENT AT 0-256  
  ORG 80h  
CmdL
CmdLen DB ?  
Command DB 127 DUP (?)  
PSP ENDS    
  .DATA    
Msg DB 'My command tail is |'  
  .CODE    
CmdTail PROC    
  mov ax, @data  
  mov ds, ax  
  ASSUME es:PSP  
  _PutStr Msg  
  mov bl, CmdLen ; bx holds command length
  sub bh, bh  
  cmp bx, 126 ; if command lenght > 126
  jle LengthOK ; force it to fit
LengthOK:
  mov [Command + bx], '$' Mark the end of the tail
  _PutStr Command, es ; Command not in .DATA segment
  ASSUME ds : PSP ; For documentation purposes
  _PutCh '|', 13, 10  
  _Exit 0  
CmdTail ENDP    
  END CmdTail  

One last requirement, EXTRN symbols must be declared in the same segment (name) in which the symbol is actually defined.


UMBC | CSEE