_Watchdogs for Interrupt Monitoring_
by Rolf V. Oestergaard 

Listing One 
   MOV AL,[NmiIntFlag]      ; Get flag
    CMP AL,3                ; Cleared by timer int?
    JNZ @@GoOn              ; No, skip
    MOV [NmiIntFlag],2      ; Yes, set again
    JMP @@Exit              ; Done for now
@@GoOn:
    CMP AL,2                ; Already set by NMI?
    JNZ @@Exit              ; No, Done for now
    MOV [NmiIntFlag],1      ; Yes, set triggered!
    MOV DX,[BP+4]           ; Get program pointer
    MOV [NmiIntErrSeg],DX   ;  from the stack.
    MOV DX,[BP+2]           ; Record segment
    MOV [NmiIntErrOfs],DX   ;  and offset
@@Exit:

Listing Two
    MOV AL,[NmiIntFlag]     ; Get flag
    CMP AL,0                ; Off?
    JZ  @@Exit              ; Yes, skip everything
    CMP AL,1                ; Triggered?
    JNZ @@Exit              ; No, skip 
    MOV [NmiIntFlag],0      ; Set off
    MOV BX,[NmiIntErrSeg]   ; Get segment
    MOV CX,[NmiIntErrOfs]   ; Get offset
    MOV AL,ERR_IntSlip      ; Get error code
    CALL    WriteError      ; Write error message and address
   MOV [NmiIntFlag],3      ; Set on again
@@Exit:

Listing Three
    MOV AX,[WatchdogCount]
    CMP AX,0FFFFh           ; Disabled?
    JZ  @@Exit              ; Yes, skip
    OR  AL,AH               ; Down?
    JZ  @@Exit              ; Yes, skip
    DEC [WatchdogCount]     ; Decrement count
    JNZ @@Exit              ; If not 0, skip ahead
    MOV DX,[BP+4]
    MOV [NmiWdErrSeg],DX    ; Record segment
    MOV DX,[BP+2]
    MOV [NmiWdErrOfs],DX    ; Record offset
@@Exit:

Listing Four
    MOV AX,[WatchdogCount]
    OR  AL,AH                     ; Timed Out?
    JNZ @@Exit                    ; No, skip
    CMP AX,0FFFFh                 ; Off?
    JZ  @@Exit                    ; Yes, skip
    MOV [WatchdogCount],WDTIMEOUT ; Yes, restart
    MOV BX,[NmiWdErrSeg]          ; Get segment
    MOV CX,[NmiWdErrOfs]          ; Get offset
    MOV AL,ERR_Watchdog           ; Get error code
    CALL    WriteError            ; Write error message and address
@@Exit:

Listing Five
MOV DX,PDATA0               ; Get I/O port address
IN  AX,DX
    XOR AH,040h             ; Toggle the WD port
    OUT DX,AX
CMP [WatchdogCount],0       
    JZ  @@Exit              ; Skip if timed out
    CMP [WatchdogCount],0FFFFh
    JZ  @@Exit              ; Skip if OFF
MOV [WatchdogCount],WDTIMEOUT   ; Set SW WD counter
@@Exit:





