Изучение принципов обработки аппаратных прерываний, страница 5


sseg SEGMENT STACK

      db 64 dup (?)

sseg ENDS

dseg SEGMENT PARA PUBLIC 'DATA'

      cnt dw 0h

      sec dw 0h

      min dw 0h

      hour dw 0h

      flag dw 0h

adr_int8:

      ipsave_8 dw 0h              

      cssave_8 dw 0h

adr_int60: 

      ipsave_60 dw 0h        

      cssave_60 dw 0h  

      msg db '   :  :  $'

dseg ENDS

cseg SEGMENT

main proc FAR

      ASSUME      cs:cseg, ds:dseg, ss:sseg

start:

      ; Data segment init

      mov ax, dseg     

      mov ds, ax

      ; Get int8 handler adress

      mov ax,3508h

      int 21h

      mov ipsave_8, bx 

      mov ax, es

      mov cssave_8, ax

      ; Get int60h handler adress

      mov ax,3560h

      int 21h

      mov ipsave_60, bx

      mov ax, es

      mov cssave_60, ax

      push ds

      mov dx, offset int_8   

      mov ax, seg int_8

      mov ds, ax       

      ; Set out int8h handler

      mov ah, 25h            

      mov al, 8h       

      int 21h                

      pop ds

      push ds

      mov dx, offset int_60  

      mov ax, seg int_60     

      mov ds, ax       

      ; Set our int60h handler

      mov ah, 25h            

      mov al, 60h      

      int 21h                

      pop ds

time:            

      ; sec check cycle

      cmp flag,0

      je exit

      mov flag,0             

      ; Convert to ASCII

      mov ax,sec

      mov bl,10              

      div bl

      add ax,3030h     

      mov word ptr es:msg+7,ax

      mov ax,min       

      div bl                      

      add ax,3030h           

      mov word ptr es:msg+4,ax

      mov ax,hour            

      div bl                      

      add ax,3030h           

      mov word ptr es:msg+1,ax

      ; Color Display

      mov ax,0B800h    

      mov es,ax

      lea bx,msg             

      ; Where to display

      mov di,0

mn1:

      mov al,[bx]

      cmp al,'$'

      je exit

      mov es:[di],al

      inc di

      inc bx

      mov es:[di],word ptr 0F0h

      inc di

      jmp mn1

exit:

      cmp min,2

      jne time

      mov ax,0h                   

      ; Working with klav

      int 16h

      push ds

      mov dx, ipsave_8

      mov ax, cssave_8

      mov ds, ax

      ; Restore int8h native handler

      mov ah, 25h

      mov al, 8h

      int 21h

      pop ds

      push ds

      mov dx, ipsave_60

      mov ax, cssave_60

      mov ds, ax

      ; Exit

      mov ah, 25h

      mov al, 60h

      int 21h

      pop ds

      ; Exit

      mov ah,4ch       

      int 21h

main  ENDP

int_8 proc FAR              

      push ax                

      push es                     

      mov ax, dseg

      mov es,ax

      ; Count int8 interrupts

      mov ax,word ptr es:cnt

      inc ax

      ; If 18 interrupts -> call int60h

      cmp ax,18        

      jne m0                 

      int 60h

      mov ax,0

m0:

      mov word ptr es:cnt,ax

      pop es

      pop ax