【问题标题】:Doing interrupt chaining assignment进行中断链接分配
【发布时间】:2011-02-24 23:41:48
【问题描述】:

正如标题所说,我正在尝试进行中断链接。我正在寻找的是,当调用定时器中断(IRQ 0)并且中断处理程序(ISR)完成时,它会执行我的代码。我正在尝试在汇编、C 或任何允许我这样做的语言上做到这一点。我在page 上找到了一个示例,但它不适用于 TASM。你能帮我解决这个问题吗,或者我在哪里可以找到这方面的信息?谢谢你。 :D

【问题讨论】:

  • 链式中断处理高度依赖于工作环境(操作系统、芯片等),而且从来都不是最常见的编程方式。您可能应该更具体地了解您正在开发的系统类型,即使如此,也可能需要耐心等待。
  • 我正在通过 VirtualBox 在 Windows XP 上工作。

标签: c assembly interrupt interrupt-handling


【解决方案1】:

我不再使用它,只是想再次使用我在组装过程中给出的第一步的汇编器:

.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

【讨论】:

  • 你做的真棒!谢谢! :D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多