A86 Assembler
A86 assembler, eh? There's a name for people like you - but I can't spell it.

This page contains programs written for the A86 assembler. They are probably also suitable for other assemblers.

References

TSR Programming
Examples (including assembled programs): tsrs.zip.

Setting Interrupt Vectors
TSR's usually hook interrupts so they can activate themselves when appropriate. This means editing the entry in the Interrupt Vector Table for the interrupt you want to hook, so that it points to your handler.
Interrupt 21h: Function 25h does this for us.

INT 21 - DOS 1+ - SET INTERRUPT VECTOR
	AH = 25h
	AL = interrupt number
	DS:DX => new interrupt handler
Example: hookint1.txt.
This program does not actually create a resident interrupt handler, it simply points the handler for Int 1Bh (Hardware response to Ctrl-Break) to F0F0:F0F0, the start of the BIOS boot commands.

Memory Resident Handlers
To create our own handler for an interrupt we must:

  • a) Point the interrupt vector for the interrupt to our handler.
    We have already seen how to set an interrupt vector.
  • b) Terminate with the handler resident in memory.
    Interrupt 21h: Function 31h allows us to terminate but remain resident.
    INT 21 - DOS 2+ - TERMINATE AND STAY RESIDENT
    	AH = 31h
    	AL = return code
    	DX = number of paragraphs to keep resident
Example: ctrl-b1.txt.
This program replaces the standard interrupt handler for INT 1Bh with my own, which prints a short string. It is easily modified to print a slightly more appropriate message, like 'Ctrl-Break Disabled'
I have not used the Interrupt 21h: Output String function, because it hangs the PC if Ctrl-Break is pressed while waiting for user input, like at the DOS prompt.

Calling the Old Handler
So we can call the old handler from our new handler we must save a pointer to it in a memory variable, before we replace it with ours.
This is done using Interrupt 21h: Function 35h

INT 21 - DOS 2+ - GET INTERRUPT VECTOR
	AH = 35h
	AL = interrupt number
Return: ES:BX -> current interrupt handler
Example: ctrl-b2.txt.
This program does that and jumps to the old handler at the end of the new one.
Note: It is then the old handler which performs the IRET!
The result is that Ctrl-Break now prints the 'Hello World' message, but then performs the normal Ctrl-Break response.

Another Example
Example: monoff.txt.
This program also hooks INT 1Bh, but this time I have used the handler to toggle power-saving monitors between their On and Standby modes.