【问题标题】:Assembly Language 8086 Keyboard and Mouse Interrupt汇编语言 8086 键盘和鼠标中断
【发布时间】:2014-12-03 00:34:55
【问题描述】:

我无法弄清楚如何为我的矩阵程序实现键盘和鼠标中断,以便在按下键盘上的任何键和/或移动鼠标时终止我的永无止境的矩阵程序就像按下鼠标上的任何按钮一样。

这是我的矩阵代码:

    title lab9 (lab9.asm)

.model small
.stack 100h
.data

    seed dw 1234h   
 .code
main proc
mov ax, @data
mov ds, ax



    mov ax, 0B800h
    mov es, ax  

    mov bx, 0
    mov ax, 0 

    Loo1:
        add bx, 120
        call row  
        call busyWait
        mov si, 0
        jmp Loo1
        loop Loo1

    mov ax,4C00h
    int 21h

main endp
row proc    

      push cx 
      mov cx, 10   

      R:  
      call printMsg 
      add bx, 160

      loop R

      pop cx


      ret
row endp



printMsg proc

    call randomCh
    mov ah, [si]
    mov es:[bx], ax
    inc si 

    ret
printMsg endp 

randomCh proc
    mov ax, 343Fh
    mul seed
    xor dx, dx
    add ax, 269h
    mov seed, ax     

    ret
randomCh endp


busyWait proc  
       push cx
       mov cx, 100h
    L1: 


    loop L1 
    pop cx

    ret
busyWait endp      

My_int proc 
mov ax, 4C00h
int 21h
iret
My_int endp

end 

这是我教授给我的键盘中断代码

mov ax, @data
mov ds, ax
;Install interrupt handler
push ds
mov ax, @code
mov ds, ax
mov ah, 25h
mov al, 9
mov dx, offset My_Int
int 21h
pop ds

Loop2;

;MATRIX CODE GOES HERE

jmp Loop2

;mov ax, 4c00h
;Int 21h
main endp

My_int proc 
mov ax, 4c00h
int 21h
iret
My_Int endp
end main

这是我的教授还给我的鼠标中断代码

.model smal
.stack 100h
.data
oX dw 0
oY dw 0
.code
main proc

    mov ax, @data
    mov ds, ax

    moov ax, 3
    int 33h
    mov oX, CX
    mov oY, DX

L1:

cmp oX ,CX ; (While oX == cx, && oY == dx && button == 0) <-- I believe the "button variable is 
           ; the BX register             
jne exit
cmp oY, DX
jne exit
cmp bx, 0
jne exit

;Matrix code goes here probably with the "Loop2: ;Matrix goes here loop Loop2 section from the
;keyboard interrupt section

mov ax, 3
int 33h
jmp L1

exit:
mov ax, 4C00H
int 21h
main endp
end main

所以我基本上必须将键盘和鼠标中断代码合并为一个,这样当运行我的程序的任何人都可以通过按下键盘上的一个键、移动鼠标​​或单击鼠标上的按钮来终止它(左单击、右键单击和中间按钮)。

对于键盘终止部分,我相信我的教授告诉我们,我们只需将代码粘贴到代码的“Loop2: ;Matrix code goes here loop Loop2”部分,但我很确定我只是听错了他.我相信他的意思是说我们必须将代码粘贴到该循环中并检查键盘键输入,但我知道这不是我知道如何检查输入的方式(mov ah 7h/1h,int 21h) 所以我对那部分感到困惑。

至于鼠标中断部分,似乎我的教授给了我我需要的一切,我只需将我的代码粘贴到鼠标中断代码的“;矩阵代码在这里”部分。如果这不正确,请告诉我,如果可能的话,请向我解释,如果可能的话,请举例说明我需要什么来使鼠标中断工作。

【问题讨论】:

    标签: assembly interrupt x86-16 keyboardinterrupt


    【解决方案1】:

    我想提供一点帮助:

    My_int proc 
    ; mov ax, 4c00h ; This is the functions number for to terminate the program.
    ; int 21h       ; Both instructions are not needed here and it is a very wrong
                    ; place for it, because all of the following instructions can
                    ; not be execute after terminating the program.
    
    ; It make more sense to push all of the register that we use here to the stack.
    push ax
    
    ; But before we want to return from the interrupt with iret, we have to send
    ; an End of Interrupt signal(EOI) to the programmable interupt controller(PIC).
    mov al, 20h
    out 20h, al
    
    ; And here we can pop all the register that we have pushed before.
    pop ax
    
    iret
    My_Int endp
    end main
    

    终止函数:“AH=4Ch int 21h”仅在父程序是子程序的调用者时,用于终止主程序并返回DOS或返回父程序。但在中断服务例程 (ISR) 中这是没有意义的。

    ;-------

    为了使用mouseinterrupt 33h,我们必须启动一个mousedriver,就像之前的cutemouse驱动一样。 http://cutemouse.sourceforge.net/

    可爱的鼠标驱动器支持串行 COM 端口和 PS/2 鼠标的协议。 (对于 USB,我们需要在主板 bios 中启用 USB lagacy。这会将 USB 数据从鼠标重定向到键盘控制器,因此 USB 鼠标可以像 PS2 鼠标一样使用。)

    【讨论】:

    • 真的吗?这很奇怪,因为我的教授告诉我,我只需要将我的代码粘贴到他给我们的代码的选定区域中。
    猜你喜欢
    • 2015-09-03
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-26
    • 2022-11-25
    相关资源
    最近更新 更多