System programs - help manage resources and typically stay resident in memory.
TSRs consist of two parts: 1) a transient portion installs the TSR 2) a resident portion is the system code that stays around in memory.
Normally, TSRs are .COM files which limit the program size to 64K bytes. The basic format of a TSR is:
code segment
assume cs:code, ds:code
org 100h
top: jmp tsr_install
old_vec dd ?
new_vec PROC FAR
; new interrupt handler code
new_vec ENDP
tsr_install: ; Save old vector pointer
; Update vector table with new vector pointer
; Specify amount of code to keep resident in memory
code ends
end top
Program Segment Prefix (PSP) is a special 256-byte block at the beginning of a program. This is why there is an org 100h assembler directive at the beginning of the program.Let's examine more closely what tsr_install needs to look like:
tsr_install: mov ax, cs
mov ds, ax
mov ah, 35h
mov al, 16h
int 21h ; bx = segment returned
; es = offset returned for int 16h
mov word ptr old_vec[0], bx ; save segment addr of old vector
mov word ptr old_vec[2], es ; save offset addr of old vector
mov dx, offset new_vec
mov ah, 25h
mov al, 16h
int 21h ; copy new vector to vector table
mov dx, offset tsr_install ; dx points to tsr routine
int 27h ; install tsr
code ends
end top