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 40H*4

	ORG 1000H
	XOR BX,BX
	MOV ES,BX
	
	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
	
	;8255 INITTIALIZATION PPI
	MOV AL, 10000000B
	OUT PPIC_C,AL
	MOV AL,11111111B
	OUT PPIA,AL
	MOV AL,00000000B
	OUT PPIC,AL
	MOV AH,11110001B
	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 INITTIALIZATION PIT
P_INIT PROC NEAR
	PUSH AX
	MOV AL,01110000B
	OUT CTCC,AL
	
	MOV AX,0FFFFH
	OUT CTC1,AL
	MOV AL,AH
	OUT CTC1,AL
	POP AX
	RET
P_INIT ENDP

;8259 INITTIALIZATION	PIC
INIT PROC NEAR
	;ICW1
	MOV AL,00010011B
	OUT INTA,AL
	;ICW2 INTERRUPT VECTOR
	MOV AL,40H
	OUT INTA2,AL
	;ICW4
	MOV AL,00000001B
	OUT INTA2,AL
	;INTERRUPT MASK
	MOV AL,11111110B
	OUT INTA2,AL
	RET
INIT	ENDP

CODE ENDS
END	