如何打印鼠标坐标TASM

时间:2014-08-15 09:40:15

标签: assembly x86 mouse interrupt tasm

TITLE MP3
.model small
.stack 100h
.data 
x  dw 0     
nwln db 13,10,"$" 
y  dw 0     
coordsx db "X: $"
coordsy db "Y: $"   

.code     

printf proc
    mov dx,bx
    mov ah,09h
    int 21h
    ret
printf endp

newline proc
    lea dx,nwln
    mov ah,09h
    int 21h
    ret
newline endp

scanf proc
    mov dx, bx
    mov ah, 0ah
    int 21h
    ret
scanf endp 


getx proc



    ret
getx endp   

START:
    MOV AX,@data
    MOV DS,AX
    mov ES,AX



    mov al,13h
    mov ah,0
    int 10h

        mov ax, 0
        int 33h

        mov ax, 1
        int 33h


     lea bx,coordsx
     call printf
     call newline
     lea bx, coordsy
     call printf
     call newline
     call newline   
     lea bx,line
     call printf
     call newline
     lea bx, circle
     call printf


      mov cx, 0002
    mov dx, 0024

start1:  



    mov x,cx
    mov y,dx  

    lea bx,coordsx
     call printf


    mov ax, 3
    int 33h     




    jmp start1


fin:
       mov ah,4ch
       int 21h        

end start

我们坚持使用此代码,我们需要打印鼠标的坐标。我们知道鼠标坐标是cx和dx但我们无法在循环内显示它。我们打印了" x:"和" Y:"在循环之外所以它不会打印多次。实时跟踪鼠标坐标

示例输出:              X:1ABC              Y:0020

1 个答案:

答案 0 :(得分:0)

您唯一需要做的就是将整数转换为字符串。这可以简单地完成:

; AX = number to be printed
; DS:DI = location for the string
itoa:
    pusha
    mov cx, ax  
    mov bx, 10
    divloop:
        xor dx, dx
        div bx  

        add dl, 48          ;start of the ASCII table
        mov byte [di], dl
        inc di

        test ax, ax 
        jnz divloop

    mov byte [di], 0
    popa
    ret

必须调用此程序

somePlaceInMemory: times 6 db 0 

....

lea bx, coordsx
call printf

mov ax, bx
mov di, somePlaceInMemory
call itoa
mov bx, di
call printf