Q:

Displaying input wrong in a 2-digit Calculator program using int 10h BIOS mouse + keyboard

I am making a mouse operated, 2-digit calculator in assembly. However I am having problems with displaying the input. The program displays the current input just fine, however the column where it's suppose to input it is wrong. Here is the entire code for making the UI :
mov ax, 06h ;ENTER GRAPHICS MODE
int 10h

mov ax, 1   ;SHOW MOUSE CURSOR
int 33h

mov cx, 20  ;INITIALIZE MOUSE CURSOR LEFT SIDE
mov dx, 20
mov ax, 4
int 33h

ui:
    mov dh, 1   ;TOP AND BOTTOM INITIAL ROW
    mov dl, 31  ;TOP AND BOTTOM INITIAL COLUMN
    mov al, '#'

    TopBottom:  ;TOP AND BOTTOM BORDER
        mov ah, 02h ;TOP    ;SET CURSOR POSITION
        int 10h
        mov ah, 0eh ;TELETYPE
        int 10h

        mov dh, 14
        mov ah, 02h ;BOTTOM
        int 10h
        mov ah, 0eh
        int 10h

        mov dh, 1
        inc dl
        cmp dl, 49
        jne TopBottom

    mov dh, 2   ;LEFT AND RIGHT INITIAL ROW
    mov dl, 31  ;LEFT AND RIGHT INITIAL COLUMN

    LeftRight:  ;LEFT AND RIGHT BORDER
        mov ah, 02h ;LEFT
        int 10h
        mov ah, 0eh ;TELETYPE
        int 10h

        mov dl, 48  
        mov ah, 02h ;RIGHT
        int 10h
        mov ah, 0eh ;TELETYPE
        int 10h

        mov dl, 31
        inc dh
        cmp dh, 14
        jne LeftRight

    mov dh, 4   ;MIDDLE INITIAL ROW
    mov dl, 32  ;MIDDLE INITIAL COLUMN

    Middle: ;MIDDLE LINE
        mov ah, 02h
        int 10h

        mov ah, 0eh
        int 10h

        inc dl
        cmp dl, 48
        jne Middle

    mov dh, 6   ;CONTENT INITIAL ROW
    mov dl, 34  ;CONTENT INITIAL COLUMN
    mov al, 55  ;7

Content:    ;NUMBERS, OPERATIONS, AND EVERYTHING IN BETWEEN!!! :D
    mov cx, 0

    Num:    ;1-9
        mov ah, 02h
        int 10h

        mov ah, 0eh
        int 10h

        add dl, 3
        inc al
        inc cx 
        cmp cx, 3
        jne num

    add dh, 2
    mov dl, 34
    sub al, 6
    cmp al, 46
    jne Content

    ;PRINTING ADDITION SYMBOL
    mov dh, 6
    mov dl, 44
    mov al, 43

    mov ah, 02h
    int 10h

    mov ah, 0eh
    int 10h

    ;PRINTING SUBTRACTION SYMBOL
    mov dh, 8
    mov al, 45

    mov ah, 02h
    int 10h

    mov ah, 0eh
    int 10h

    ;PRINTING MULTIPLICATION SYMBOL
    mov dh, 10
    mov al, 42

    mov ah, 02h
    int 10h

    mov ah, 0eh
    int 10h

    ;PRINTING DIVISION SYMBOL
    mov dh, 12
    mov al, 47

    mov ah, 02h
    int 10h

    mov ah, 0eh
    int 10h    

    ;PRINTING ZERO    
    mov dh, 12  ;ZERO ROW
    mov dl, 34  ;ZERO COLUMN
    mov al, 48

    mov ah, 02h
    int 10h

    mov ah, 0eh
    int 10h

    ;PRINTING C (RESTART)
    mov dl, 37
    mov al, 99

    mov ah, 02h
    int 10h

    mov ah, 0eh
    int 10h

    ;PRINTING EQUALS SYMBOL
    mov dl, 40
    mov al, 61

    mov ah, 02h
    int 10h

    mov ah, 0eh
    int 10h

The code below is the one that displays the input on screen, however the counter doesn't seem to be working. Although I'm adding 1, it adds 2 during the first loop and doesn't add anything to it after. I'm new to assembly so I might be missing or misusing some of the registers. Please help
mov bl, 0   ;COUNTER
func:
    mov ax, 0003h
    int 33h

    cmp bx, 0
    je func

    mov ax, 0004h   ;SET THE MOUSE CURSOR
    int 33h

    add bl, 1

    ;COMPARE ROW
    cmp cx, 286
    jl col1

    cmp cx, 310
    jl col2

    ;cmp cx, 334
    jmp col3

    col1:
        cmp dx, 59
        jl seven

        cmp dx, 76
        jl four

        cmp dx, 92
        jl one

        cmp dx, 108
        jl zero

    seven:
        mov al, 55
        jmp input

    four:
        mov al, 52
        jmp input

    one:
        mov al, 49
        jmp input

    zero:
        mov al, 48
        jmp input

    col2:
        cmp dx, 59
        jl eight

        cmp dx, 76
        jl five

        cmp dx, 92
        jl two

        cmp dx, 108
        jl thing

    eight:
        mov al, 56
        jmp input

    five:
        mov al, 53
        jmp input

    two:
        mov al, 50
        jmp input

    thing:
        jmp ui

    col3:
        cmp cx, 334
        jg col4

        cmp dx, 59
        jl nine

        cmp dx, 76
        jl six

        cmp dx, 92
        jl three

        cmp dx, 108
        jl equals

    nine:
        mov al, 57
        jmp input

    six:
        mov al, 54
        jmp input

    three:
        mov al, 51
        jmp input

    equals:
        jmp exit

    col4:
        cmp dx, 59
        jl addition

        cmp dx, 76
        jl subtraction

        cmp dx, 92
        jl multiplication

        cmp dx, 108
        jl division

    addition:
        mov al, 43
        jmp input

    subtraction:
        mov al, 45  
        jmp input

    multiplication:
        mov al, 42
        jmp input

    division:
        mov al, 47
        jmp input

input:
    mov dl, 42  ;SET INITIAL COL OF INPUT
    mov dh, 2   ;SET INITIAL ROW OF INPUT
    add dl, bl
    mov ah, 02h
    int 10h
    mov ah, 0eh
    int 10h

jmp func

exit:  

int 20h

A:

mov bl, 0   ;COUNTER
func:
    mov ax, 0003h
    int 33h
    cmp bx, 0
    je func
    mov ax, 0004h   ;SET THE MOUSE CURSOR
    int 33h
    add bl, 1

You expect to keep a counter in the BL register, but you missed the fact that the call to get the mouse position returned the button status in the BX register. This inevitably destroys your counter because BL is the low 8 bits of BX!
You could choose to put this counter in another free register like BP:
    xor bp, bp     ;COUNTER=0
func:
    mov ax, 0003h
    int 33h
    cmp bx, 0
    je  func
    mov ax, 0004h  ;SET THE MOUSE CURSOR
    int 33h
    inc bp         ;COUNTER+1

Also note that most BIOS functions you use expect you to specify the display page in the BH register. (You don't do this at all!) This is another reason why it is not a good idea to keep the counter in the BL/BX register.

