Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 单击鼠标一次可重复多次_Assembly_X86_X86 16_Tasm_Dosbox - Fatal编程技术网

Assembly 单击鼠标一次可重复多次

Assembly 单击鼠标一次可重复多次,assembly,x86,x86-16,tasm,dosbox,Assembly,X86,X86 16,Tasm,Dosbox,我正在做一个利用鼠标的组装项目(TASM和DOSBox)。 当用户单击屏幕上的某个区域时,会打印出某条消息 我的问题是,只要按下鼠标按钮(每次单击3或4次),计算机就会继续打印消息 我试图保存最后按下的按钮,并防止打印消息,如果同一个按钮连续按下两次,你可以在下面的代码中看到,但它似乎不起作用。我也知道有一种方法可以获取按钮释放信息,但我似乎也无法让它工作 有人知道我能做些什么来解决这个问题,或者用不同的方法吗?谢谢 IDEAL MODEL small STACK 0f500h mou

我正在做一个利用鼠标的组装项目(TASM和DOSBox)。 当用户单击屏幕上的某个区域时,会打印出某条消息

我的问题是,只要按下鼠标按钮(每次单击3或4次),计算机就会继续打印消息

我试图保存最后按下的按钮,并防止打印消息,如果同一个按钮连续按下两次,你可以在下面的代码中看到,但它似乎不起作用。我也知道有一种方法可以获取按钮释放信息,但我似乎也无法让它工作

有人知道我能做些什么来解决这个问题,或者用不同的方法吗?谢谢

IDEAL
MODEL small
STACK 0f500h

    mouse_last_button dw 1  ;holds the value of last mouse button clicked
    mouse_button dw 0       ;holds the value of mouse button clicked
    counter dw ?
    x_clicked dw ?
    y_clicked dw ?
    half_button dw 9
    arr_length dw 76
    clear_x dw 229
    clear_y dw 137

CODESEG

;================PROCEDURES================
proc setGraphic
    ;sets graphic mode
    mov ax, 13h
    int 10h
    ret
endp setGraphic
;-----------------
proc initMouse
    ;initializes mouse
    mov ax, 0
    int 33h ;resets mouse
    mov ax, 1
    int 33h ;shows pointer
    ret
endp initMouse
;-----------------
proc initImage
    ;imports keyboard bitmap
    mov [BmpLeft],0
    mov [BmpTop],99
    mov [BmpColSize], 320
    mov [BmpRowSize] ,101
    mov dx,offset SmallPicName
    call OpenShowBmp
    ret
endp initImage
;-----------------
proc getMouseClick
    mov ax, [mouse_button] ;stores the value of the last state of the mouse
    mov [mouse_last_button], ax
    mov ax,3
    int 33h ;gets mouse information
    shr cx, 1   ;halves the x position value since the interrupt returns double

    mov [mouse_button],bx   ;saves the click's button, x and y position
    mov [x_clicked],cx  
    mov [y_clicked],dx
    ret
endp getMouseClick
;-----------------
proc checkMouseButton
    ret
endp checkMouseButton
;-----------------
proc checkXR
    ;check if click is not more than 9 pixels right to the center (of the button)
    mov bx, offset x_arr
    add bx,[counter]
    mov ax,[bx]
    add ax,[half_button]
    ret
endp checkXR
;-----------------
proc checkXL
    ;check if click is not more than 9 pixels left to the center
    mov ax,[bx]
    sub ax,[half_button]
    ret
endp checkXL
;-----------------
proc checkYT
    ;check if click is not more than 9 pixels above the center
    mov bx, offset y_arr
    add bx,[counter]
    mov ax,[bx]
    sub ax,[half_button]
    ret
endp checkYT
;-----------------
proc checkYB
    ;check if click is not more than 9 pixels below the center
    mov ax,[bx]
    add ax,[half_button]
    ret
endp checkYB
;-----------------
proc printLetter
    ;prints the character at button that was clicked
    mov bx, offset letter_arr   
    mov ax,[counter]
    shr ax,1    ;halves counter since letter_arr is byte sized and counter is word sized
    add bx,ax
    mov dx, [bx]
    mov ah, 2
    int 21h
    ret
endp printLetter
;-----------------
;================PROCEDURES================

start:
    mov ax,@data
    mov ds,ax

    call setGraphic ;sets graphic mode
    call initMouse ;initializes mouse
    call initImage  ;displays keyboard's image

    mov cx, [arr_length] ;iterates over all of the buttons in the keyboard until one matches a click's location
    mov [counter],cx

mouseLoop:
    call getMouseClick

    mov ax, [mouse_button]      ;waits for the user to click left mouse button
    cmp ax, 1
    jne doLoop
    cmp ax,[mouse_last_button]  ;if button pressed before is the same as the current one, wait for another press
    je mouseLoop

    call checkXR    ;checks X right
    cmp [x_clicked],ax
    ja searchAgain

    call checkXL    ;checks X left
    cmp [x_clicked],ax
    jb searchAgain

    call checkYT    ;checks Y top
    cmp [y_clicked],ax
    jb searchAgain

    call checkYB    ;checks Y bottom
    cmp [y_clicked],ax
    jb writeLetter

searchAgain:
    ;precedes to the next button in the array 
    mov cx,[counter]
    dec [counter]
    cmp cx,0
    jnz mouseLoop
    jmp doLoop

writeLetter:
    call printLetter    ;prints the letter found
    call initImage  ;restarts the keyboard image
    mov ax, 1
    int 33h ;shows pointer

doLoop:
    ;starts iterating over arrays again
    mov cx,[arr_length]
    mov [counter],cx
    jmp mouseLoop

exit:
    mov ax, 4c00h
    int 21h
END start
还有一件事要提:当我

    cmp ax,[mouse_last_button]
    jne mouseLoop
对于je(实际上应该是这样),什么也没发生。

我找到了一个解决方案。 我删除了:

    cmp ax,[mouse_last_button]
    je mouseLoop
并补充说:

waitForRelease: 
    call getMouseClick
    mov ax,[mouse_button]
    cmp ax,0
    jne waitForRelease

就在进入等待用户释放鼠标按钮的循环的
writeLetter
之后,然后继续。

所有这些变量在哪里声明?您是否错误地将它们中的任何一个声明为字节而不是单词?否。这两个按钮都是单词大小,起始值分别为1和0。这与几天前的一个问题非常相似:正如michael指出的,我们不知道您是如何在标签上声明数据的(以及它们的大小)。如果您将此作为一个示例,并显示演示problemUpdate的完整代码,将会有所帮助:“等待发布”循环建议正在工作。谢谢