Почему увеличивается число циклов, при вызове прерывания с клавиатуры, программы в защищенном режиме?
Для программы перехвачен системный таймер. Клавиатура в этом режиме отключена, тк неописана в таблице дескрипторов для прерывании.
Код:
;prg17_1.asm
;Attention! tasm /m2 prg17_1,,,
.386P
.MODEL large
delay MACRO time
local ext, iter
push cx
mov cx, time
ext:
push cx
mov cx, 65000
iter:
loop iter
pop cx
loop ext
pop cx
ENDM
descr STRUC
limit dw 0
base_1 dw 0
base_2 db 0
attr db 0
lim_atr db 0
base_3 db 0
ENDS
load_descr MACRO des,seg_addr,seg_size
mov des.limit,seg_size
xor eax,eax
mov ax,seg_addr
shl eax,4
mov des.base_1,ax
rol eax,16
mov des.base_2,al
ENDM
atr MACRO descr,bit1,bit2,bit3
atr_&descr=constp or bit1 or bit2 or bit3
ENDM
point STRUC
lim dw 0
adr dd 0
ENDS
descr_idt STRUC
offs_1 dw 0
sel dw 30h
no_use db 0
type_attr db 8eh
offs_2 dw 0
ENDS
constp equ 10010000b
code_r_n equ 00010000b
code_r_y equ 00000010b
data_wm_n equ 00000000b
data_wm_y equ 00000010b
code_n equ 00000000b
code_p equ 00000100b
data_ equ 00000000b
stack_ equ 00000000b
code_ equ 00001000b
data_stk equ 00000000b
stk segment stack 'stack'
db 256 dup (0)
stk ends
gdt_seg segment para public 'data' use16
gdt_0 descr <0,0,0,0,0,0>
atr gdt_gdt_8,data_wm_y,data_,data_stk
gdt_gdt_8 descr <0,0,0,atr_gdt_gdt_8,0,0>
gdt_ldt_10 descr <0,0,0,0,0,0>
atr gdt_ds_18,data_wm_y,data_,data_stk
gdt_ds_18 descr <0,0,0,atr_gdt_ds_18,0,0>
atr gdt_vbf_20,data_wm_y,data_,data_stk
gdt_es_vbf_20 descr <0,0,0,atr_gdt_vbf_20,0,0>
atr gdt_ss_28,data_wm_y,stack_,data_stk
gdt_ss_28 descr <0,0,0, atr_gdt_ss_28,0,0>
atr gdt_cs_30,code_r_y,code_n,code_
gdt_cs_30 descr <0,0,0,atr_gdt_cs_30,0,0>
gdt_size=$-gdt_0-1
gdt_seg ends
idt_seg segment para public 'data' use16
REPT 20h
descr_idt <dummy,,,,>
ENDM
int20h descr_idt <new_08h,,,,>
int21h descr_idt <sound,,,,>
REPT 222
descr_idt <dummy,,,,>
ENDM
idt_size=$-idt_seg-1
idt_seg ends
data segment para public 'data' use16
point_gdt point <gdt_size,0>
point_idt point <idt_size,0>
char db '0'
maskf db 07h
position dw 2000
tonelow dw 2651
temp dw 0
cnt db 0
data_size=$-point_gdt-1
data ends
code segment byte public 'code' use16
assume cs:code,ss:stk
dummy proc
;mov ax,0ffffh
db 66h
iret
endp
sound PROC
assume ds:data
push ax
push cx
push dx
mov al,0b6h
out 43h,al
in al,61h
or al,03h
out 61h,al
go:
mov cx, 2083
musicup:
mov ax,tonelow
out 42h,al
xchg ah,al
out 42h,al
delay 50
inc tonelow
mov dx,tonelow
mov temp,dx
loop musicup
mov cx,2083
musicdown:
mov ax,temp
out 42h,al
xchg ah,al
out 42h,al
delay 50
dec temp
loop musicdown
mov dx,temp
mov tonelow,dx
inc cnt
cmp cnt,2
jnz go
in al,61h
and al,11111100b
out 61h,al
pop dx
pop cx
mov al,20h
out 20h,al
pop ax
db 66h
iret
ENDP
new_08h proc
assume ds:data
push ds
push es
push ax
push bx
mov ax,20h
mov es,ax
scr:
mov al,char
mov ah,maskf
mov bx,position
mov es:[bx],ax
add bx,2
mov position,bx
inc char
pop bx
pop ax
pop es
pop ds
mov al,20h
out 20h,al
db 66h
iret
endp
new_8259a proc
push ax
mov al,00010001b
out 20h,al
jmp $+2
jmp $+2
pop ax
out 21h,al
jmp $+2
jmp $+2
mov al,00000100b
out 21h,al
jmp $+2
jmp $+2
mov al,00000001b
out 21h,al
ret
endp
main proc
mov ax,stk
mov ss,ax
assume ds:GDT_SEG
mov ax,GDT_SEG
mov ds,ax
load_descr gdt_gdt_8,GDT_SEG,gdt_size
load_descr gdt_ds_18,DATA,data_size
load_descr gdt_es_vbf_20,0b800h,3999
load_descr gdt_ss_28,STK,255
load_descr gdt_cs_30,CODE,code_size
assume ds:data
mov ax,data
mov ds,ax
xor eax,eax
mov ax,GDT_SEG
shl eax,4
mov point_gdt.adr,eax
lgdt point_gdt
cli
mov al,80h
out 70h,al
mov al,20h
call new_8259A
xor eax,eax
mov ax,IDT_SEG
shl eax,4
mov point_idt.adr,eax
lidt point_idt
mov eax,cr0
or al,1
mov cr0,eax
db 0eah
dw offset protect
dw 30h
protect:
mov ax,18h
mov ds,ax
mov ax,20h
mov es,ax
mov ax,28h
mov ss,ax
sti
delay 15000
int 21h
cli
mov al,08h
call new_8259A
assume ds:GDT_SEG
mov ax,8h
mov ds,ax
mov gdt_ds_18.limit,0ffffh
mov gdt_es_vbf_20.limit,0ffffh
mov gdt_ss_28.limit,0ffffh
mov gdt_cs_30.limit,0ffffh
assume ds:DATA
mov ax,18h
mov ds,ax
mov ax,20h
mov es,ax
mov ax,28h
mov ss,ax
db 0eah
dw offset jump
dw 30h
jump: mov eax,cr0
and al,0feh
mov cr0,eax
db 0eah
dw offset r_mode
dw CODE
r_mode:
mov ax,DATA
mov ds,ax
mov ax,STK
mov ss,ax
mov ax,3ffh
mov point_idt.lim,ax
xor eax,eax
mov point_idt.adr,eax
lidt point_idt
sti
xor al,al
out 70h,al
mov ax,4C00h
int 21h
main ENDP
code_size=$-dummy
code ends
end main
;Attention! tasm /m2 prg17_1,,,
.386P
.MODEL large
delay MACRO time
local ext, iter
push cx
mov cx, time
ext:
push cx
mov cx, 65000
iter:
loop iter
pop cx
loop ext
pop cx
ENDM
descr STRUC
limit dw 0
base_1 dw 0
base_2 db 0
attr db 0
lim_atr db 0
base_3 db 0
ENDS
load_descr MACRO des,seg_addr,seg_size
mov des.limit,seg_size
xor eax,eax
mov ax,seg_addr
shl eax,4
mov des.base_1,ax
rol eax,16
mov des.base_2,al
ENDM
atr MACRO descr,bit1,bit2,bit3
atr_&descr=constp or bit1 or bit2 or bit3
ENDM
point STRUC
lim dw 0
adr dd 0
ENDS
descr_idt STRUC
offs_1 dw 0
sel dw 30h
no_use db 0
type_attr db 8eh
offs_2 dw 0
ENDS
constp equ 10010000b
code_r_n equ 00010000b
code_r_y equ 00000010b
data_wm_n equ 00000000b
data_wm_y equ 00000010b
code_n equ 00000000b
code_p equ 00000100b
data_ equ 00000000b
stack_ equ 00000000b
code_ equ 00001000b
data_stk equ 00000000b
stk segment stack 'stack'
db 256 dup (0)
stk ends
gdt_seg segment para public 'data' use16
gdt_0 descr <0,0,0,0,0,0>
atr gdt_gdt_8,data_wm_y,data_,data_stk
gdt_gdt_8 descr <0,0,0,atr_gdt_gdt_8,0,0>
gdt_ldt_10 descr <0,0,0,0,0,0>
atr gdt_ds_18,data_wm_y,data_,data_stk
gdt_ds_18 descr <0,0,0,atr_gdt_ds_18,0,0>
atr gdt_vbf_20,data_wm_y,data_,data_stk
gdt_es_vbf_20 descr <0,0,0,atr_gdt_vbf_20,0,0>
atr gdt_ss_28,data_wm_y,stack_,data_stk
gdt_ss_28 descr <0,0,0, atr_gdt_ss_28,0,0>
atr gdt_cs_30,code_r_y,code_n,code_
gdt_cs_30 descr <0,0,0,atr_gdt_cs_30,0,0>
gdt_size=$-gdt_0-1
gdt_seg ends
idt_seg segment para public 'data' use16
REPT 20h
descr_idt <dummy,,,,>
ENDM
int20h descr_idt <new_08h,,,,>
int21h descr_idt <sound,,,,>
REPT 222
descr_idt <dummy,,,,>
ENDM
idt_size=$-idt_seg-1
idt_seg ends
data segment para public 'data' use16
point_gdt point <gdt_size,0>
point_idt point <idt_size,0>
char db '0'
maskf db 07h
position dw 2000
tonelow dw 2651
temp dw 0
cnt db 0
data_size=$-point_gdt-1
data ends
code segment byte public 'code' use16
assume cs:code,ss:stk
dummy proc
;mov ax,0ffffh
db 66h
iret
endp
sound PROC
assume ds:data
push ax
push cx
push dx
mov al,0b6h
out 43h,al
in al,61h
or al,03h
out 61h,al
go:
mov cx, 2083
musicup:
mov ax,tonelow
out 42h,al
xchg ah,al
out 42h,al
delay 50
inc tonelow
mov dx,tonelow
mov temp,dx
loop musicup
mov cx,2083
musicdown:
mov ax,temp
out 42h,al
xchg ah,al
out 42h,al
delay 50
dec temp
loop musicdown
mov dx,temp
mov tonelow,dx
inc cnt
cmp cnt,2
jnz go
in al,61h
and al,11111100b
out 61h,al
pop dx
pop cx
mov al,20h
out 20h,al
pop ax
db 66h
iret
ENDP
new_08h proc
assume ds:data
push ds
push es
push ax
push bx
mov ax,20h
mov es,ax
scr:
mov al,char
mov ah,maskf
mov bx,position
mov es:[bx],ax
add bx,2
mov position,bx
inc char
pop bx
pop ax
pop es
pop ds
mov al,20h
out 20h,al
db 66h
iret
endp
new_8259a proc
push ax
mov al,00010001b
out 20h,al
jmp $+2
jmp $+2
pop ax
out 21h,al
jmp $+2
jmp $+2
mov al,00000100b
out 21h,al
jmp $+2
jmp $+2
mov al,00000001b
out 21h,al
ret
endp
main proc
mov ax,stk
mov ss,ax
assume ds:GDT_SEG
mov ax,GDT_SEG
mov ds,ax
load_descr gdt_gdt_8,GDT_SEG,gdt_size
load_descr gdt_ds_18,DATA,data_size
load_descr gdt_es_vbf_20,0b800h,3999
load_descr gdt_ss_28,STK,255
load_descr gdt_cs_30,CODE,code_size
assume ds:data
mov ax,data
mov ds,ax
xor eax,eax
mov ax,GDT_SEG
shl eax,4
mov point_gdt.adr,eax
lgdt point_gdt
cli
mov al,80h
out 70h,al
mov al,20h
call new_8259A
xor eax,eax
mov ax,IDT_SEG
shl eax,4
mov point_idt.adr,eax
lidt point_idt
mov eax,cr0
or al,1
mov cr0,eax
db 0eah
dw offset protect
dw 30h
protect:
mov ax,18h
mov ds,ax
mov ax,20h
mov es,ax
mov ax,28h
mov ss,ax
sti
delay 15000
int 21h
cli
mov al,08h
call new_8259A
assume ds:GDT_SEG
mov ax,8h
mov ds,ax
mov gdt_ds_18.limit,0ffffh
mov gdt_es_vbf_20.limit,0ffffh
mov gdt_ss_28.limit,0ffffh
mov gdt_cs_30.limit,0ffffh
assume ds:DATA
mov ax,18h
mov ds,ax
mov ax,20h
mov es,ax
mov ax,28h
mov ss,ax
db 0eah
dw offset jump
dw 30h
jump: mov eax,cr0
and al,0feh
mov cr0,eax
db 0eah
dw offset r_mode
dw CODE
r_mode:
mov ax,DATA
mov ds,ax
mov ax,STK
mov ss,ax
mov ax,3ffh
mov point_idt.lim,ax
xor eax,eax
mov point_idt.adr,eax
lidt point_idt
sti
xor al,al
out 70h,al
mov ax,4C00h
int 21h
main ENDP
code_size=$-dummy
code ends
end main
- почему цикл, зависящий от системного таймера, увеличивает многократно число итерации при нажатии любой клавиши? от darksvesh, 19 декабря 2012 года