
   ORG 001BH 
INTERRUPT_1: 
   PUSH  ACC 
   PUSH  PSW 
   CLR   TR1 
   MOV   PSW, #00H 
   ACALL KEYPRESSED 
   JNZ   CALCULATE 
   JB    FLAG_SECOND, HALT1 ; if no key is pressed and earlier
                            ; the key were presed taking into 
   JB    FLAG_FIRST, COOL   ; account the 1st & 2nd press, then
                            ; jump to HALT1 and only once key 
   JMP   AGAIN              ; is pressed then jump to COOL or
                            ; jump to AGAIN

CALCULATE: 
   ACALL KEYPRESSED         ; again check whether any key is
                            ; pressed or not
   JZ    HALT               ; if no key is pressed then jump 
                            ; to halt for checking the key 
                            ; is pressed ;before or not by 
                            ; cheking the flag ... FLAG_FIRST 
   ACALL CONVERT            ; check the validity of the key 
                            ; pressed 
   JBC   FLAG_INVALIDKEY, HALT ; if the key pressed is invalid
                               ; then jump to HALT 
   INC   R0                 ; increment R0 fro checking 
                            ; whether the key is pressed first
                            ; time or not 
   CJNE  R0, #01, COMPARE   ; if the key is not pressed for 
                            ; the first time then jump to
                            ; COMPARE 
   MOV   NEWKEY, A          ; here it shows the key is pressed 
                            ; for the first time and so the
                            ; fresh key ;is taken to a new flag
                            ; named NEWKEY for further checking
                            ; on second time key hit 
   SETB  FLAG_FIRST         ; set this flag which shows the key
                            ; is pressed 1st time, this flag is
                            ; used while the checking the in 
                            ; the subroutine HALT 
   JMP   OUTPUT             ; jump to output the 1st time
                            ; keypressed 
