3932695
3932695

Reputation: 87

Need help hooking new keyboard interrupt in MS-DOS

I am working on an assignment for an assembly class.

I have previously managed to make my timer interrupt display and update a 'clock' at every tick.

I am attempting to use this knowledge to replace my keyboard interrupt. But even when I comment out the installation of the new keyboard interrupt handler, my program is interfering with MS-DOS activities (i.e. cannot run any executables, can only use 'dir', 'cd' and similar commands):

.model tiny
.8086
.code
        org 100h
start:
        jmp setup

new_key PROC
        jmp cs: old_key
new_key ENDP

setup:
        mov ax, cs
        mov ds, ax

        old_key DD 00000000h

        MOV    AL, 9h                 ;+-
        MOV    AH, 35h                  ;| Save old_key
        INT    21h                     ;|
        MOV    WORD PTR [old_key],BX
        MOV    WORD PTR [old_key][2],ES


        ; cli   
        ; PUSH   CS                      ;| Install new_key
        ; POP    DS                      ;|
        ; LEA    DX, new_key
        ; MOV    AL, 9h
        ; MOV    AH, 25h
        ; INT    21h


        cli
        push ds
        LDS    DX,CS:[old_key]         ;+- 
        MOV    AL, 9h                  ;| Disinstall new_key
        MOV    AH, 25h                  ;| 
        INT    21h
        POP    DS
        STI   


        mov ax, TSR
        int CALLDOS

end start

Since there are problems even when I've commented out the installation, I think the problem lies with the disinstallation or the old_key saving. I do not know what is wrong however; shouldn't the installation and disinstallation code be essentially similar timer interrupt's install/disinstall code?

Assistance would be appreciated, thank you in advance.

Upvotes: 0

Views: 1773

Answers (1)

Michael
Michael

Reputation: 58467

    mov ds, ax

    old_key DD 00000000h

    MOV    AL, 9h                 ;+-

You shouldn't mix code and data like that. The CPU has no knowledge of old_key not being code, so it will happily try to execute it. Either move the variable to before the setup label, or insert a jump instruction to skip past it.

Upvotes: 1

Related Questions