2011-02-24 44 views
1

正如標題所說,我正在嘗試執行中間鏈接。我正在尋找的是,當定時器中斷(IRQ 0)被調用,並且中斷處理程序(ISR)完成時,它會執行我的代碼。我試圖用Assembly,C或任何允許我這樣做的語言來完成它。我在這個page上找到了一個例子,但它在TASM上不起作用。你能幫我解決這個問題嗎,或者我可以找到關於這方面的信息?謝謝。 :d做中斷鏈接任務

+1

連鎖中斷處理是高度依賴於工作環境(操作系統,芯片等),並且未曾最常見方式來編程。您應該更具體地瞭解您正在從事的是什麼類型的系統,即使如此,耐心也可能是有條件的。 – dmckee

+0

我正在使用VirtualBox上的Windows XP。 – Osukaa

回答

2

我不使用它了,只是想與可能我給裝配了第一步彙編再次發揮:

.186 
.MODEL TINY, C 

.code 
ORG 100h 

Entry: 
; Install handler 
    push ds 
    xor cx, cx 
    mov ds, cx 
    mov ax, ds:[8*4] 
    mov dx, ds:[8*4+2] 
    cli 
    mov ds:[8*4], OFFSET InterruptHandler 
    mov ds:[8*4+2], cs 
    pop ds 
    mov word ptr [OldIntVect], ax 
    mov word ptr [OldIntVect+2], dx 
    sti 

; Wait for the user to press a key. In the meantime you should see lots of wildcards! 
    xor ax, ax 
    int 16h 

; Restore original handler 
    mov ax, word ptr [OldIntVect] 
    mov dx, word ptr [OldIntVect+2] 
    push ds 
    xor cx, cx 
    mov ds, cx 
    cli 
    mov ds:[8*4], ax 
    mov ds:[8*4+2], dx 
    sti 
    pop ds 

; Exit to DOS 
    int 20h 

PROC MyHandler 

    mov ah, 0Eh 
    mov al, '*' 
    int 10h 
    ret 
ENDP 


InterruptHandler: 
    pushf 
    call cs:[OldIntVect] 
    cmp [busy], 0 
    jne ExitHandler ; If jumps then the timer was faster than the time it takes for MyHandler to complete 

    mov cs:[busy], 1 
    pusha 
    call MyHandler ; Other options are using a pointer to function or just inlining the code here. 
    popa 
    mov cs:[busy], 0 

ExitHandler: 
    iret 

OldIntVect dd ? 
busy  db ? 

END Entry 

的WinXP(32位)下測試:

>tasm timer.asm 
Turbo Assembler Version 1.01 Copyright (c) 1988, 1989 Borland International 

Assembling file: TIMER.ASM 
Error messages: None 
Warning messages: None 
Remaining memory: 481k 


>tlink /t timer.obj 
Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International 

>timer 
*************************** 

但是,這當然只適用於DOS環境(DOSBox,Windows 32位版本等),並且最多隻需調整一次引導加載程序。

無論如何,感謝美麗的時候,你只給我恢復這一切:P

+0

驚人的你怎麼做到了!謝謝! :d – Osukaa