Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › assembly language

Terminate and Stay Resident (TSR): What It Means in MS-DOS

By Freedom251 Team · · 2 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Terminate and stay resident (TSR) is a DOS technique in which a program ends its initial run and returns control to its parent while keeping selected code and data in memory. That retained portion can later provide a service or respond to an event. In MS-DOS, the documented method is Interrupt 21h, function 31h.

What does TSR stand for?

TSR stands for terminate and stay resident. “Terminate” means the program’s initial execution ends and control returns to the program that started it. “Stay resident” means a chosen part of the program remains allocated in memory rather than being released with the rest of the running program.

As an Amazon Associate I earn from qualifying purchases.

The term is associated with DOS programs. It does not mean the program continues running continuously in the background: its resident code is reached later through an interrupt handler or another entry point.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How does a TSR work?

  1. Install: The program initializes and may register an interrupt handler or another way for later code to reach it.
  2. Keep the resident portion: It calls a DOS termination service that returns control to its parent while retaining a specified amount of memory.
  3. Respond later: A subsequent interrupt, software call, or other documented entry point transfers control to the retained code.

The setup code and the resident code need not occupy the same amount of memory. A program can leave only the portion needed for its later work resident.

#1 Best Overall

How MS-DOS terminates a program but keeps it in memory

INT 21h function 31h

MS-DOS documents INT 21h function 31h as the terminate-and-stay-resident service. The calling program sets AH to 31h, places its return code in AL, and specifies the number of memory paragraphs to retain in DX. The service ends the running program, passes the return code to its parent, and keeps the specified memory resident. The Assembly Language Help reference for INT 21h function 31h describes the inputs and behavior; Microsoft’s MASM 6.1 Programmer’s Guide (1992) identifies function 31h as an MS-DOS service invoked through Interrupt 21h.

These are historical MS-DOS interfaces. For a new implementation, consult documentation for the specific DOS version or environment you intend to support rather than assuming low-level behavior is identical everywhere.

INT 27h

INT 27h is an older terminate-and-stay-resident method. Microsoft’s MASM 6.1 guide says it is present in the MS-DOS versions covered by that guide, but warns that Microsoft could not guarantee future support and did not recommend relying on it. That is a historical recommendation about the DOS interface, not a statement about support in present-day operating systems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What were TSR programs used for?

TSRs could provide services to other programs or respond to events without being loaded from disk for each use. Microsoft’s MS-DOS Programmer’s Reference, Including Version 5 (1991) gives PRINT.EXE as an example: it remains resident to maintain a print queue and provide functions other programs can call. A Microsoft KnowledgeBase article on TSRs in assembly, last modified January 12, 1989, describes a timer-interrupt example. The Programmer’s WorkBench TSR glossary entry also mentions pop-up utilities.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What distinguishes one TSR from another?

When discussing TSR implementations, the useful differences are technical rather than product comparisons:

Quick Recap

SaleBestseller No. 1
Bestseller No. 3
Bestseller No. 4
Running MS-DOS: Qbasic
Running MS-DOS: Qbasic
Used Book in Good Condition
$6.67
Rank #4
Running MS-DOS: Qbasic
  • Used Book in Good Condition
  • Termination call: INT 21h function 31h or the older INT 27h.
  • Memory retained: how much memory, and which portion of the program, remains resident.
  • Activation method: an interrupt handler, software interrupt, or another documented entry point.
  • Purpose: a service for other programs, device support, or an interactive utility.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

assembly languagecomputer terminologyDOSMS-DOSTSR

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.