Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 100h
- .data
- mouseX dw 0 ; Mouse X coordinate
- mouseY dw 0 ; Mouse Y coordinate
- num_text db 5 dup('0'),10,13, '$'
- number_size db 0
- .code
- IMPRIMIR MACRO text
- lea dx, text
- mov ah, 09h
- int 21h
- ENDM
- posicion macro x, y
- mov ah, 02H
- mov bh, 00h
- mov dl, x
- mov dh, y
- int 10H
- endm
- JMP_NOT_CLICKED MACRO not_clicked
- mov ax, 3
- int 33h
- test bx, 1
- jz not_clicked
- endm
- main proc
- mov ax,@data
- mov ds, ax
- ;set video mode (320x200, 256 colors)
- mov ax, 13h
- int 10h
- call init_mouse
- coord_loop:
- JMP_NOT_CLICKED not_mouse
- call get_mouse_pos
- not_mouse:
- call PrintMousePos
- jmp coord_loop
- ret
- main endp
- init_mouse proc
- mov ax,0
- int 33h
- mov ax,1
- int 33h
- ret
- init_mouse endp
- get_mouse_pos proc
- mov ax,3
- int 33h
- shr cx, 1
- mov [mouseX], cx
- mov [mouseY], dx
- ret
- get_mouse_pos endp
- ;------IMPRIMIR------
- PrintMousePos proc
- posicion 0, 0
- mov ax,mouseX
- mov number_size,3
- call NumberToString
- IMPRIMIR num_text
- mov ax,mouseY
- call NumberToString
- IMPRIMIR num_text
- ret
- PrintMousePos endp
- NumberToString proc
- push cx
- xor cx,cx ;How many numbers have been written
- lea di, num_text
- cmp ax, 0 ; Check if AX is 0
- je zeroNumber
- mov bx, 10 ; BX = 10 for division
- divideLoop:
- xor dx, dx ; Clear DX for division
- div bx ; AX / 10, quotient in AL, remainder in DX
- add dl, '0' ; ASCII
- push dx ; Remainder
- inc cx
- test ax, ax ; Check if quotient is zero
- jnz divideLoop
- reverseDigits:
- pop dx ; Pop a digit from stack
- mov [di], dl ; Store the digit
- inc di ; Move to next position in buffer
- loop reverseDigits
- jmp checkPadding
- zeroNumber:
- mov [di],'0'
- inc di
- checkPadding:
- mov ax,di
- sub ax, offset num_text
- cmp al, number_size
- jge setTerminator
- mov byte ptr [di], '_' ; Add a space for padding
- inc di
- dec bx
- jmp checkPadding
- setTerminator:
- mov [di], 10
- mov [di+1],13
- mov [di+2], '$'
- pop cx
- ret
- NumberToString endp
- end
Advertisement
Add Comment
Please, Sign In to add comment