DOS Fn 31H: Terminate & Stay Resident

                                                         Compatibility: 2.0+ 
 Expects: AH    31H
          AL    exit code to be made available to fn 4dH
          DX    memory size to keep resident, in 16-byte paragraphs
 Returns: none  (not applicable)
    Info: Exits to the parent process, leaving code and data in memory and
          setting the exit code in AL.  See TSR for related topics.

          DOS sets the initial memory allocation (at your PSP segment
          address) to the size specified by DX and returns control to the
          parent process, keeping that much memory resident (bytes
          remaining resident = DX * 16).

          This function also performs the following actions:
          ■ Flushes file buffers and closes all open files.
          ■ Sets the INT 22H vector to the value at PSP:000AH.
          ■ Sets the INT 23H vector to the value at PSP:000EH.
          ■ Sets the INT 24H vector to the value at PSP:0012H (2.0+).

   Notes: ■ This DOES NOT free up any other blocks allocated via Fn 48H.

            It's wise to free your environment block beforehand (call
            Fn 49H with ES= the WORD at PSP offset 2cH).

          ■ This function supersedes INT 27H which does not return an exit
            code and can't install resident programs larger than 64K.

See Also: TSR
          Process Control
          Program Startup & Exit
          DOS Functions