问题
Is there any other way to disable interrupts for the duration of only one instruction in x86 than using the CLI instruction?
回答1:
Yes, loading SS with a MOV will inhibit external interrupts for the next instruction. This is what the instruction set reference says:
Loading the SS register with a MOV instruction inhibits all interrupts until after the execution of the next instruction. This operation allows a stack pointer to be loaded into the ESP register with the next instruction (MOV ESP, stack-pointer value) before an interrupt occurs.
回答2:
This code snippet does the trick:
pushf
pop ax
and ax, FDFFh
push ax
popf ;This disables interrupts, You didn't use "CLI"
; Here IF is clear
sti
来源:https://stackoverflow.com/questions/33330911/how-to-disable-interrupts-for-one-instruction