Assembly on DOS (TASM), creating TSR with a new handler on int 21h

孤街醉人 提交于 2020-01-05 06:47:25

问题


I have a trouble with making TSR com file for DOS. It should set a new handler on a 21'th interrupt, terminate and stay resident. New handler should transfer control to an old interrupt 21h handler. I save its interrupt vector, but have no idea how to call it correctly. Here is a program:

.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

回答1:


My 16-bit DOS ASM is a bit rusty, but if I recall correctly you need to do this:

push word ptr [old_int21h + 2] ; segment
push word ptr [old_int21h]     ; offset
retf



回答2:


I understood the problem. The right solution is here. "Right" isn't sure "optimal", but works nice anyway, and it isn't hard enough to optimize this code now.

.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

The answer below was almost right :)



来源:https://stackoverflow.com/questions/15119745/assembly-on-dos-tasm-creating-tsr-with-a-new-handler-on-int-21h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!