; One-second beeper. TSR COM-file "program" that intercepts the 
; timer tick interrupt to output a beep once every second.
; Illustrates how to write an ISR for a PC.

code    segment
        assume  cs:code
        org     100h
main:   jmp     ldnvec
oldvec  dd      ?       ;Will hold old INT 8 vector
count   dw      18      ;18 timer ticks = 1 second

;This is our new INT 8 ISR
;If 18 timer ticks have gone by, output "beep character"
newisr: push    ax              ;Save altered register
        dec     cs:count
        jnz     exit
        mov     cs:count,18
        mov     ax,0e07h        ;INT 10h, service 0Eh outputs...
        int     10h             ;character 07 -- a beep
exit:   pop     ax              ;Restore altered register
        jmp     cs:oldvec       ;Go to old INT 8 ISR

ldnvec: ;*** This code executes only once--installs the new vector ***
        ;Get and save old int 8 vector (Use INT 21h, service 35h)
        ;Set up new int 8 vector (Use INT 21h, service 25h)
        ;                   (offset: newisr, base: CS or DS)
        ;Terminate leaving everything up to ldnvec resident
        ;                   (Use INT 21h, service 31h)   
code    ends
        end     main