External interruption refers to the interruption that no longer occurs inside the CPU, that is, the interruption of peripherals that communicate with the CPU through the port.
- Blocked interruptions are external interruptions that the CPU does not respond
- Unshielded interrupt is the interrupt that the CPU must respond to, where the interrupt type code is 2
- STI and CLI can block interruptions and ensure the security of operations such as changing the interrupt vectors.
1. the interrupt can be shielded. The CPU determines whether to respond to the interrupt based on the if bit of the Flag register. If = 1, the response is interrupted, if = 0, and no response is interrupted.
STI, used to set if = 1;
CLI, used to set if = 0.
2. the interrupt cannot be blocked, and the CPU must respond to the interrupt. The value of the unshielded interrupt type code is fixed to 2. Therefore, the interrupt type code is not required during the interruption process. The process of interruption that cannot be blocked is:
(1) Mark Register into Stack, if = 0, TF = 0;
(2) Loading CS and IP addresses into the stack;
(3) (IP) = (8), (CS) = (0ah ).
Program 1: Output A ~ at a certain position on the screen ~ Z, Press ESC to change the color of the location. The execution speed of each computer may be different, and the latency can be modified as appropriate.
Assume Cs: Code
Stack segment
DB 128 DUP (0)
Stack ends
Data Segment
DW 0, 0
Data ends
Code segment
Start:
MoV ax, stack
MoV SS, ax
MoV SP 128
MoV ax, Data
MoV ds, ax
MoV ax, 0
MoV es, ax
Push ES: [9*4]
Pop DS: [0]
Push ES: [9*4 + 2]
Pop DS: [2]
MoV word ptr es: [9*4], offset int9
MoV ES: [9*4 + 2], CS
MoV ax, 0b800h
MoV es, ax
MoV ah, 'A'
S: mov ES: [160*12 + 40*2], ah
Call Delay
INC ah
CMP ah, 'Z'
JNA s
MoV ax, 0
MoV es, ax
Push ds: [0]
Pop ES: [9*4]
Push ds: [2]
Pop ES: [9*4 + 2]
MoV ax, 4c00h
Int 21 h
Delay:
PUSH AX
Push DX
MoV dx, 10 h
MoV ax, 0
S1:
Sub ax, 1; SBB command with bitwise subtraction 0-1 = FFFF, cf = 1
SBB dx, 0; (dx) = (dx)-0-cf
CMP ax, 0; equivalent to FFFF * 1000 times
JNE S1
CMP dx, 0
JNE S1
Pop DX
Pop ax
RET
Int9: PUSH AX
Push BX
Push es
In Al, 60 h
Pushf
Pushf
Pop BX
And BH, 11111100b
Push BX
Popf
Call dword ptr ds: [0]
CMP Al, 1
JNE int9ret
MoV ax, 0b800h
MoV es, ax
INC byte ptr es: [160*12 + 40*2 + 1]; add a property value to change the color
Int9ret: Pop es
Pop BX
Pop ax
Iret
Code ends
End start
Program 2: Press F1 to change the screen color.
CS always at the high address
Assume Cs: codesg, SS: stacksg
Stacksg segment
DW 64 DUP (0)
Stacksg ends
Codesg segment
Start: mov ax, stacksg
MoV SS, ax
MoV SP 128
MoV ax, 0
MoV es, ax
MoV ax, codesg
MoV ds, ax
MoV Si, offset int9s
MoV Di, 0200 H
CLI
MoV BX, Offset Table
MoV ax, ES: [9*4]
MoV [BX], ax
MoV ax, ES: [9*4 + 2]
MoV [bx + 2], ax
MoV word ptr es: [9*4], 0200 H
MoV word ptr es: [9*4 + 2], 0
STI
MoV CX, offset int9end-offset int9s
ClD
Rep movsb
MoV ax, 4c00h
Int 21 h
Int9s: JMP short SSS
Table DW 0, 0
SSS: PUSH DS
PUSH AX
Push CX
Push Si
Pushf
MoV ax, 0
MoV ds, ax
Call dword ptr ds: [202 h]
In Al, 60 h
CMP Al, 3bh
JNE int9ret
MoV Si, 0
MoV CX and 2000
MoV ax, 0b800h
MoV ds, ax
S1: Inc byte PTR [Si + 1]
Add Si, 2
Loop S1
Int9ret: Pop Si
Pop CX
Pop ax
Pop DS
Iret
Int9end: NOP
Codesg ends
End start
Program 3: in DOS, press the 'A' key and release it to display the screen full of 'A '.
The order in which the stack is interrupted is pushf, push CS, and push IP.
Assume Cs: codesg, SS: stacksg
Stacksg segment
DW 64 DUP (0)
Stacksg ends
Codesg segment
Start: mov ax, stacksg
MoV SS, ax
MoV SP 128
MoV ax, 0
MoV es, ax
MoV Di, 0200 H
MoV Si, offset int9
Push CS
Pop DS
CLI
MoV BX, Offset Table
MoV ax, ES: [9*4]
MoV DS: [BX], ax
MoV ax, ES: [9*4 + 2]
MoV DS: [bx + 2], ax
STI
MoV CX, offset int9end-offset int9
ClD
Rep movsb
MoV word ptr es: [9*4 + 2], 0
MoV word ptr es: [9*4], 0200 H
MoV ax, 4c00h
Int 21 h
Int9: JMP short S
Table DW 0, 0
S: PUSH AX
Push CX
Push Si
Push es
MoV ax, 0
MoV ds, ax
Pushf
Call dword ptr ds: [202 h]
In Al, 60 h
CMP Al, 9eh
JNE int9ret
MoV ax, 0b800h
MoV es, ax
MoV Si, 0
MoV CX and 2000
S1: mov byte ptr es: [Si], 'A'
Add Si, 2
Loop S1
Int9ret: Pop es
Pop Si
Pop CX
Pop ax
Iret
Int9end: NOP
Codesg ends
End start