Assembly Language (Intel 8086) – Mouse Interrupts (Emu8086)

I posted this short code in my DeVry GSP 130 class, as a sample code to print out mouse coordinate.

The first thing we have to do is to initialize the mouse using INT 33h / AX=0000, then we could request the mouse information using INT 33h / AX=0003.
If needed, INT 33h / AX=0000 and INT 33h / AX=0001 show and hide the mouse pointer respectively.

Image Hosted by ImageShack.us

; Sylvia Wei
; MouseCoordinate.asm
; This DOS program prints the current mouse coordinate on the screen.
; Credits: TheColonial at Kirupa Forum for the clear_screen subroutine.

org 100h
include ‘emu8086.inc’

jmp CodeStart

DataStart:

xMsg db “X: “, “$”
yMsg db ” Y: “, “$”
endl db 13, 10, “$”

CodeStart:

MOV ax,0000
INT 33h

start:

PRINT_STRING xMsg

MOV ax,0003
INT 33h
MOV ax, cx
CALL print_num

PRINT_STRING yMsg
MOV ax, dx
CALL print_num

; CALL clear_screen ;Uncomment this line, and comment out ‘PRINT_STRING endl’ to only show one line at a time.
PRINT_STRING endl
CMP bx, 1 ;exit if left mouse button is held

JNE start

ret

PRINT_STRING macro string

; display a string terminated by $
; dx contains address of string
PUSH DX
PUSH AX
LEA DX, string
MOV AH, 9h ; print messg func
INT 21h ; output string
POP AX
POP DX

ENDM

clear_screen PROC

PUSHA
MOV AH, 6
MOV AL, 0
MOV BH, 7
MOV CX, 0
MOV DL, 79
MOV DH, 24
INT 10h
MOV AH, 2
MOV BH, 0
MOV DH, 0
MOV DL, 0
INT 10h
POPA
RET

clear_screen ENDP

DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS

For further information, feel free to comment and ask your questions or check out the bios and dos interrupt instruction set at http://www.emu8086.com/assembly_language_tutorial_assembler_reference/8086_bios_and_dos_interrupts.html

And now, excuse me while I interrupt myself. – Murray Walker

Leave a Reply

You must be logged in to post a comment.