I am trying to write TSR (Terminate-Stay-Resident) (in general) programs in Assembly (16-bit) for MS-DOS. I read the WSR page on TSR, as well as the page about using it specifically in DOS (but it seems to teach it in C, and not in the assembly directly). I went through a website with tons of documentation on DOS interrupts and found this , this , and the other most relevant to TSR programs. I canβt post all the links, because as a new user I can have up to 2 hyperlinks in the message.
So, I tried writing (apparently) a very simple TSR program in real mode (.COM file format) in NASM. Here is the code:
[BITS 16] [ORG 0x0100] [SECTION .text] Start: ; Get current interrupt handler for INT 21h mov AX,3521h ; DOS function 35h GET INTERRUPT VECTOR for interrupt 21h int 21h ; Call DOS (Current interrupt handler returned in ES:BX) mov WORD [v21HandlerSegment],ES ; Store the current INT 21h handler segment mov WORD [v21HandlerOffset],BX ; Store the current INT 21h handler offset ; Write new interrupt handler for INT 21h mov AX,2521h ; DOS function 25h SET INTERRUPT VECTOR for interrupt 21h mov DX,TSRStart ; Load DX with the offset address of the start of this TSR program ; DS already contains the segment address, it is the same as CS in this .COM file int 21h ; Override the INT 21h handler with this TSR program ; The TSR program will be called even when this portion uses INT 21h to terminate and stay resident mov AX,3100h ; DOS function TSR, return code 00h mov DX,00FFh ; I don't know how many paragraphs to keep resident, so keep a bunch int 21h ; Call our own TSR program first, then call DOS TSRStart: push WORD [v21HandlerSegment] ; Push the far address of the original push WORD [v21HandlerOffset] ; INT 21h handler onto the stack retf ; Jump to it! [SECTION .data] v21HandlerSegment dw 0000h v21HandlerOffset dw 0000h
When I collect this and execute it inside DOS, instead of returning back to the DOS prompt, it hangs up by the system (no action happens, except that the hardware cursor simply blinks below the last prompt). I think memory junk can execute, but you understand the point.
Can someone help or figure out what the problem is with this code, and / or offer general guidelines for coding TSR in DOS? Thanks in advance, any help is greatly appreciated!
Alex Ozer
source share