CODE   SEGMENT 
  ASSUME           CS: CODE, DS: CODE, ES: CODE, SS: CODE 
  ; 
PPIC_C EQU     1FH 
PPIC     EQU     1DH 
PPIB     EQU     1BH 
PPIA     EQU     19H 
  ;   
CTC1    EQU     0BH; 
CTCC    EQU     0FH; 
  ; 
INTA    EQU     10H; 
INTA2 EQU     INTA+2;   
INT_V EQU     41H*4; 
  ; 
  ORG     1000H 
  ; 
  XOR     BX, BX; 
  MOV     ES, BX; the starting address of the extra segment is 0
  ; 
  MOV    AX, OFFSET INT_SER; 
  MOV    BX, INT_V; 
  MOV    WORD PTR ES: [BX], AX
  ; 
  XOR     AX, AX; 
  MOV    WORD PTR ES: [BX+2], AX; 
 ;
   CALL    INIT 
  CALL    P_INIT 
  ; 

  MOV    AL, 10000000B; 
  OUT     PPIC_C, AL 
  ; 
  MOV    AL, 11111111B 
  OUT     PPIA, AL; 
  ; 
  MOV    AL, 00000000B 
  OUT     PPIC, AL; port C to allow the diodes to be in forward bias 
  ; 
  MOV    AH, 11110001B; turn on the first led 
  MOV    AL, AH 
  OUT     PPIB, AL 
  STI; 
L2:        NOP 
  JMP      L2            
  ; 
  INT       3 
  ; 
  ; The Interrupt Service Routine              
INT_SER: 
  SHL      AH, 1 
  TEST     AH, 00010000B 
  JNZ       L1 
  OR        AH, 11110000B 
  JMP      L3 
  ; LED out 
L1:        MOV    AH, 11110001B 
L3:        MOV    AL, AH 
  OUT     PPIB, AL 
  ; 
  PUSH   AX 
  MOV    AX, 0ffFFH
  OUT     CTC1, AL
  MOV    AL, AH 
  OUT     CTC1, AL
  POP      AX 
  ; EOI command 
  MOV    AL, 00100000B 
  OUT     INTA, AL 
  STI 
  IRET    
  ; 8253 Initialization 
P_INIT PROC   NEAR 
  PUSH   AX 
  MOV    AL,01110110B 
  OUT     CTCC, AL  
  


  MOV    AX, 0FFFFH 
  OUT     CTC1, AL 
  MOV    AL, AH 
  OUT     CTC1,AL 


;;;;;;;;;;;;
mov al,10110110b
out ctcc,al
mov ax,0005
out 0dH,al
mov al,ah
out 0dH,al



  POP      AX 
  RET       
P_INIT ENDP 
  ; 
  ; 8259 Initialization 
INIT      PROC   NEAR 
  ; ICW1 
   MOV    AL, 00010011B 
  OUT     INTA, AL 
  ; ICW2 interrupt vector 
  MOV    AL, 41H
  OUT     INTA2, AL 
  ; ICW4 
  MOV    AL, 00000001B; 
  OUT     INTA2, AL 
  ; interrupt mask 
  MOV    AL, 11111101B
  OUT     INTA2, AL 
  RET 
INIT      ENDP 
  ;   
CODE   ENDS 
  END
