-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_1.ASM
76 lines (64 loc) · 1.94 KB
/
4_1.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
DATA SEGMENT
NUM DB 0
; the messages
MEG1 DB 'One click is received.',0DH,0AH,'$'
MEG2 DB 'Ten clicks have been received.',0DH,0AH,'$'
KEEP_CS DW 0 ; store CS
KEEP_IP DW 0 ; store IP
DATA ENDS
STACK SEGMENT PARA STACK
DW 128 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, ES:DATA, SS:STACK
INTR PROC ; interrupt procedure
INC NUM
MOV DX, OFFSET MEG1
MOV AH, 9
INT 21H ; output MEG1
MOV AL, 20H
OUT 20H, AL
IRET
INTR ENDP
START: MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV AX, STACK
MOV SS, AX ; initialize
MOV AH, 35H
MOV AL, 0BH ; the INT n number
INT 21H
MOV KEEP_IP, BX
MOV KEEP_CS, ES ; store the original CS:IP
PUSH DS
MOV DX, OFFSET INTR
MOV AX, SEG INTR
MOV DS, AX
MOV AH, 25H
MOV AL, 0BH
INT 21H
POP DS ; load the new procedure into INT 0BH
IN AL, 21H
AND AL, 11110111B
OUT 21H, AL ; activate the IRQ3 from masking
STI ; set interrupt enable
NEXT: CMP NUM, 10
JNZ NEXT ; count 10 times
MOV DX, OFFSET MEG2
MOV AH,9
INT 21H ; output message 2
IN AL, 21H
OR AL, 00001000B
OUT 21H, AL ; shutdown the IRQ3
PUSH DS
MOV DX, KEEP_IP
MOV AX, KEEP_CS
MOV DS, AX
MOV AH, 25H
MOV AL, 0BH
INT 21H ; restore the original interrupt procedure
POP DS
MOV AH,4CH
INT 21H ; end the program
CODE ENDS
END START