1

我在为 DOS 制作 TSR com 文件时遇到了麻烦。它应该在第 21 个中断时设置一个新的处理程序,终止并保持驻留。新处理程序应将控制权转移到旧的中断 21h 处理程序。我保存了它的中断向量,但不知道如何正确调用它。这是一个程序:

.model tiny
.data
    old_int21h dw ?, ?
.code
org 100h
start:

    ;saving old interrupt vector
    mov ax, 3521h
    int 21h
    mov [old_int21h], bx
    mov [old_int21h + 2], es

    ;setting new interrupt vector
    cli
    push ds
    push cs
    pop ds
    lea dx, myint21h
    mov ax, 2521h
    int 21h
    pop ds
    sti

    ; TSR
    lea dx, start
    int 27h

myint21h proc
    ; doing something
    ; want to transfer control to an old interrupt 21h handler here. How?
    iret
myint21h endp

end start
4

3 回答 3

2

我明白了这个问题。正确的解决方案就在这里。“正确”不确定“最佳”,但无论如何都很好用,现在优化这段代码还不够难。

.model tiny
.code
org 100h
start:

    ; saving old interrupt vector
    mov ax, 3521h
    int 21h
    mov [old_int21h], bx
    mov [old_int21h + 2], es

    ; setting new interrupt vector
    cli
    push ds
    push cs
    pop ds
    lea dx, myint21h
    mov ax, 2521h
    int 21h
    pop ds
    sti

    ; TSR
    mov dx, 00ffh
    mov ax, 3100h
    int 21h

    ; here comes data & hew handler part
    old_int21h dw ?, ?

    myint21h proc
                    ; some stuff
                    ; transfer control to an old interrupt 21h handler
        push word ptr [cs:old_int21h + 2] ; segment
        push word ptr [cs:old_int21h]     ; offset
        retf
    myint21h endp

end start

下面的答案几乎是正确的:)

于 2013-03-01T05:18:12.707 回答
1

我的 16 位 DOS ASM 有点生疏,但如果我没记错的话,你需要这样做:

push word ptr [old_int21h + 2] ; segment
push word ptr [old_int21h]     ; offset
retf
于 2013-02-27T19:01:23.730 回答
-1
     .model tiny
     .code
     org 100h
     start:

; Inicializando la fecha para LotusWorks
    mov ax, 2A21h
    int 21h
    mov [Reg_DX], dx
        sub cx,064h
    mov [Reg_CX], cx

; saving old interrupt vector
    mov ax, 3521h
    int 21h
    mov [old_int21h], bx
    mov [old_int21h + 2], es

; setting new interrupt vector

    cli
    push ds
    push cs
    pop ds
    lea dx, myint21h
    mov ax, 2521h
    int 21h
    pop ds
    sti

     ; TSR
    mov dx, 00ffh
    mov ax, 3100h
    int 21h

     ; here comes data & hew handler part

    old_int21h dw ?, ?
    Reg_DX     dw ?, ?
    Reg_CX     dw ?, ?

     myint21h proc

       cmp ah,2ah
       jne S1
           cmp al,56h
           je  S2
           mov ah,02h
           int 01AH
           cmp cx,0
           jne Mismodia
           mov ax,02A56h
           int 21h
      mov [CS:Reg_DX], dx

MismoDia:
       mov cx, [cs:Reg_CX]
       mov al,00
       mov dx, [cs:Reg_DX]
       iret

       S2:
           mov al,0

       S1:
        ; transfer control to an old
        ; interrupt 21h handler


        push word ptr [cs:old_int21h + 2]   ; segment
        push word ptr [cs:old_int21h]       ; offset
        retf
    myint21h endp

     end start
于 2020-02-12T14:16:18.480 回答