2013-02-27 4 views
1

DOS 용 TSR com 파일을 만드는 데 문제가 있습니다. 21 번째 인터럽트에 새로운 처리기를 설정하고 종료하고 상주해야합니다. 새 처리기는 이전 인터럽트 21h 처리기로 제어를 전송해야합니다. 그 인터럽트 벡터를 저장하지만 올바르게 호출하는 방법을 모른다. 여기에 프로그램 :DOS (TASM)에서 어셈블리, int에서 새 처리기로 TSR 만들기 2134

.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 
+0

어떤 버전인가? –

+0

DOS v.5.00에서 dosbox 사용 – gukoff

답변

1

내가 문제를 이해했다. 올바른 해결책이 여기 있습니다. "Right"가 "optimal"인지는 확실하지 않지만 어쨌든 멋지게 작동합니다. 이제이 코드를 최적화하는 것이 어렵지 않습니다.

.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 

는 아래의 대답은 거의 바로 : DOS의

1

내 16 비트 DOS ASM은 약간 녹슨이지만, 내가 올바르게 기억하는 경우에는이 작업을 수행 할 필요가 :

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

이것은 이전 핸들러로의 이동이라는 점에 유의하십시오. - 컨트롤은 사용자의 후크로 돌아 가지 않고 원본 호출자에게 직접 반환됩니다 (스택을 원래 상태로 유지 한 경우 직접 실행하지 않아도됩니다). :) –

+0

DOS에서 작동합니까? 이것을 사용할 때, dosbox는 첫 번째 int 21h 이후 정지합니다. 내 프로그램이 일반적으로 정확합니까? 스택은 그대로 유지됩니다. – gukoff

+0

불행하게도 실제로 16 비트 DOS 개발을 할 수있는 근무 환경이 실제로없는 것은 아닙니다. 뒤로 DOS ISR/TSR 작업을 할 때, SoftICE와 같은 일이 있었는데, 자주 쓰는 일이 남쪽으로 가면 도움이되었습니다.이 일은 쉽지 않습니다. –