bits 16 org 100h jmp init.tsr chk db '$$$ABz' handler: sti ; enable interrupts mov [cs:callerstk+2], ss mov [cs:callerstk], sp mov ss, [cs:tsrseg] ; mov segreg disables interrupts ; until end of next instruction mov sp, stk push ds push cs pop ds push dx push ax mov dx, msg mov ah, 0x9 int 0x21 pop ax pop dx pop ds mov ss, [cs:callerstk+2] mov sp, [cs:callerstk] iret tsrseg dw 0 msg db 'h3LL0 wOrLDD',0xd,0xa,0x24 callerstk dd 0 times 0x100 db 0 stk equ $+1 init.tsr: mov ax, 0x3565 int 0x21 mov si, chk mov di, chk mov cx, 0x6 rep cmpsb ; Check if installed jz init.fail mov [tsrseg], cs mov dx, handler mov ax, 0x2565 int 0x21 mov es, [0x2c] ; Free enviroment block if not needed mov ah, 0x49 int 0x21 mov dx, stk-1 add dx, 0xf shr dx, 0x4 mov ax, 0x3100 int 0x21 fail db 'AlReAdy iNstAleD$' init.fail: mov dx, fail mov ah, 0x9 int 0x21 mov ax, 0x4c01 int 0x21