Bx register is always equal 1 after interapt int 33h in assembly 8086

  Kiến thức lập trình

Im currently working on an assembly project and I encountered a problem, I haev a proc called ‘mouse_click’ that I need to call a couple of times in the project.
the first time the proc is being called it is working as it should, but the second time that its being called after the line ‘int 33h’ bx is always equal to one and It skips the part where I check if the mouse is clicked.
here is the code:

proc mouse_click
        
    mov ax,0h 
    int 33h       ;resets the mouse
    
    mov ax,1h 
    int 33h       ;shows the mouse
not_pressed:
    mov bx,0
    mov ax,3h 
    int 33h 
    
    cmp bx, 01h    ;checks if left mouse is pressed
    jne not_pressed 
;if left mouse is not pressed, it jumps to not_pressed and checks again if left mouse is pressed
    
    shr cx, 1   ;devide the x coordinates in 2 to get correct x coordinates
    
    mov [left_pressed_x], cx    
    ;moves the x cordinates of the mouse to left_pressed_x when left button is pressed
    
    mov [left_pressed_y], dx    
    ;moves the y cordinates of the mouse to left_pressed_y when left button is pressed      
    
    mov ax, 2h  
    int 33h
;hides the mouse because if not the coordinates of the color will be the one on the outline of the mouse so the color would never change
    
    mov bh, 0   ;sets page to zero

    mov ah, 0Dh  ; checks pixel color in mouse coordinates(left_pressed_x, left_pressed_y) 
    int 010h  
    
    ;al = color
    mov [left_pressed_color], al   
    ; moves the color to left_pressed_color 

    add [left_pressed_color], '0'
    ;turns left_pressed_color from unicode into ascii
    
    mov ax, 1 
    int 33h   ;shows the mouse agaim
    ret
endp mouse_click

I tried reseting bx before the ‘int 33h’ line and before the ‘ret’ line, but every time it gets to the ‘int 33h’ line bx is equal to one.

LEAVE A COMMENT