Sei sulla pagina 1di 14

COE119L ASSEMBLY LANGUAGE PROGRAMMING (LABORATORY)

BIOS LEVEL PROGRAMMING INT 33H FUNCTION


DRILL 7
NAME: STUDENT NUMBER: DATE OF PERFORMANCE: DATE OF SUBMISSION:

_______________________________ Professor

MAPUA INSTITUTE OF TECHNOLOGY


SCHOOL OF EECE

Laboratory Report Rubric


____________________________________________________________
(Laboratory Report Title)

Name of Student:______________________________ Date/Time of Performance:___________


Criteria
Prompt Submission

Beginner (0-1)
Report is submitted a week after the laboratory performance Untidy -Numerous marks of erasures Sheets are not stapled together crampled and most parts are missing Ink used was not clear Most fields are not completely filled Results gathered are limited, or are imprecise Incorrect answers to most questions provided in the report All codes are poorly designed and did not produce expected results. Source codes are not documented and agreed coding standards are not followed

Intermediate (23)
Report is submitted not later than a week after the performance. Evident marks of erasures All sheets are stapled together and some parts are missing Appropriate use of ink Some fields are not completely filled Results gathered are not that accurate. Most of the problems answered are correct. Some parts of the code(s) are not well designed and did not produce expected results. Source codes are partially documented and agreed coding standards are partially observed Appropriate choice of language Can express ideas Discussion was well versed.

Skilled (4-5)
Report is submitted on time. No marks of erasures All sheets are stapled together and complete Appropria te use of ink All fields are completely filled Results gathered are accurate. All problems are correctly answered. Codes are well designed and are running. Source codes are well documented and agreed coding standards are properly observed

Weigh t
5

Score

Appearance and Completeness of Report

Accuracy of Gathered Results

15

Programming Skills Used in Programming Exercises

20

Discussion of Results and Observation s

Inappropriate use of words, poor grammar and ideas are not clearly expressed Does not point out discussion well

Use of rich language, excellent grammar, and ideas are expressed precisely Discussio

15

2 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

n was clear and accurate.

Total = ( Weight * Score ) / 60 ______________________________________ Signature over Printed Name of Professor

3 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

7.1 OBJECTIVES
1. Learn mouse operations in assembly language programming using INT 33h 2. Implement INT 33h in solving problems regarding mouse operations

7.2 DISCUSSION
The mouse is usually connected to the computer's motherboard through an RS-232 serial port, a PS-2 mouse port, or a wireless connection. Before detecting the mouse, MS-DOS requires a device driver program to be installed in memory. MS-Windows also has built-in mouse drivers, but for now we will concentrate on functions provided by MS-DOS. Mouse BIOS Services MS-DOS functions for reading the mouse Mickey unit of measurement (200th of an inch) Mickeystopixels ratio (8 x 16) is variable INT 33H functions The mouse functions can be invoked by calling INT 33H which specifically handles the initialization, display, conceal, set and get process for mouse operations. The following are the mouse functions under INT 33H. Functi Description Functi Description on on 00H Initialize the mouse 14H Swap mouse-even interrupt 01H Display the mouse pointer 15H Get buffer size 02H Conceal the mouse pointer 16H Save mouse driver state 03H Get button status and pointer 17H Restore mouse driver state location 04H Set pointer location 18H Install alternative handler for mouse events 05H Get button-press information 19H Get address of alternative handler 06H Get button-release information 1AH Set mouse sensitivity 07H Set horizontal limits for pointer 1BH Get mouse sensitivity 08H Set vertical limits for pointer 1CH Set mouse interrupt rate 09H Set graphics pointer type 1DH Select display page for pointer 0AH Set pointer text type 1EH Get display page for pointer 0BH Read mouse-motion counters 1FH Disable mouse driver 0CH Interrupt handler for mouse 20H Enable mouse driver events 0DH Turn on light pen emulation 21H Reset mouse driver 0EH Turn off light pen emulation 22H Set language for mouse driver message 0FH Set mickey-to-pixel ratio 23H Get language number 10H Set pointer exclusion area 24H Get mouse information 13H Set double-speed threshold Converting Pixel to Character Coordinates Standard text fonts in MS-DOS are 8 pixels wide and 8 pixels high, so you can convert pixel coordinates to character coordinates by dividing the former by the character size. For normal mouse operation, AX or BX contains mouse button status, CX contains Xcoordinate (in pixels), and DX contains Y-coordinate after INT 33H function call. The following are the procedures used in mouse operations:

4 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

GetMousePosition PROC ; Return the current mouse position and button status. ; Receives: nothing ; Returns: BX = button status (0 = left button down, ; 1 = right button down, 2 = center button down) ; CX = X-coordinate ; DX = Y-coordinate push ax mov ax, 3 int 33h pop ax ret GetMousePosition ENDP GetButtonRelease PROC ; Receives: AX=6 ; BX = button ID (0 = left, I = right, 2 = center) ; Returns: AX = button status ; BX = button release counter ; CX = X-coordinate of last button release ; DX = Y-coordinate of last button release For button release information, a mouse click event occurs only when a mouse button is released. Similarly, a drag event ends when the mouse button is released. The mouse button status is returned in AX as follows: If bit 0 is set, the left button was released; if bit I is set, the right button was released; if bit 2 is set, the middle button was released.

7.3 LAB EXERCISES


1. Code the program below: Program Listing 7.2
.model small .data

string1 db string2 db counterStrLeft db counterStrRightdb string db countLeft countRight .386 .code main

"right click me" "left click me" "Left:" "Right:" "You have reached 10 times!" db '0' db '0'

PROC FAR mov ax, @data mov ds, ax mov es, ax ;Hide the text cursor and display the mouse call HideCursor call ClrScr call ShowMousePointer mov call mov mov dx, 0526h Gotoxy ax, 1301h bx, 0001h

5 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

lea mov mov int lea mov mov int lea mov mov int lea mov mov int mov call mov mov mov mov int mov call mov mov mov mov int

bp, string1 cx, 14 dx, 010eh 10h bp, string2 cx, 13 dx, 0120h 10h bp, counterStrLeft cx, 5 dx, 1210h 10h bp, counterStrRight cx, 6 dx, 1223h 10h dx, 1216h Gotoxy ah, 9 bx, 0001 cx, 1 al, countRight 10h dx, 122Ah Gotoxy ah, 9 bx, 0001 cx, 1 al, countLeft 10h

; display the string right click me ; row = 01, col = 0Eh to 1Ah ; display the string left click me ; row = 01, col = 20h to 2ch ; display Left:

; display Right:

; display counter value

; Loop: Check for left mouse ; button click, or for a keypress (Esc key). L1: call L2: mov int jz mov int cmp je jmp quit: mov int main Gotoxy pusha mov ah, 2 mov bh, 0 int 10h popa ret ah, 4ch 21h ENDP PROC ah, 11h 16h L1 ah, 10h 16h al, 1Bh quit L1 LeftOrRight ; check for button click

; remove key from buffer ; yes. Is it the ESC key? ; no, continue the loop

6 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

Gotoxy Clrscr pusha mov mov mov mov int mov mov mov int popa ret Clrscr

ENDP PROC ax, 0600h cx, 0 dx, 184Fh bh, 7 10h ah, 2 bh, 0 dx, 0 10h ENDP

HideCursor PROC ; Hide the text cursor by setting its top line ; value to an illegal value. mov ah, 3 int 10h or ch, 30h mov ah, 1 int 10h ret HideCursor ENDP ShowMousePointer pusha mov ax, 1 int 33h popa ret ShowMousePointer LeftOrRight ; Check for the ; ; Receives: ; Returns: ; ; pusha mov ah, 0 mov al, 5 mov bx, 0 int 33h cmp je mov mov mov int cmp je jmp left: PROC

; get cursor size ; set upper row to illegal value ; set cursor size

; make mouse cursor available

ENDP PROC most recent left mouse button press, BX = button number (0 = left, 1 = right, 2 = middle) BX = button press counter CX = X-coordinates DX = Y-coordinates ; get mouse status ; (button press information) ; specify the left button

bl, 00000001b left ah, 0 al, 5 bx, 1 33h bl, 00000001b right noleftright

; get mouse status ; (button press information) ; specify the right button

7 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

shr shr cmp jne cmp jl cmp jg inc jmp right: shr shr cmp jne cmp jl cmp jg inc noleftright: cmp je cmp je jmp quitme: call mov mov lea mov mov int mov int ret dontquitme: mov call mov mov mov mov int mov call mov mov mov mov int popa ret LeftOrRight END main

cx, 3 dx, 3 dx, 0001 noleftright cx, 0020h noleftright cx, 002ch noleftright countRight noleftright cx, 3 dx, 3 dx, 0001 noleftright cx, 000Eh noleftright cx, 001Ah noleftright countLeft countLeft, 3Ah quitme countRight, 3Ah quitme dontquitme Clrscr ax, 1301h bx, 0001h bp, string cx, 26 dx, 071Ah 10h ah, 4ch 21h dx, 122Ah Gotoxy ah, 9 bx, 0001 cx, 1 al, countLeft 10h dx, 1216h Gotoxy ah, 9 bx, 0001 cx, 1 al, countRight 10h

; 8 pixels = 1B ; Is it between the range ; of the string?

; 8 pixels = 1B ; Is it between the range ; of the string?

; has the person clicked either ; of the buttons 10 times? ; if yes, quit. if no, ; display the new value

; Show incremented value of left counter

; Show incremented value of right counter

ENDP

8 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

What is the output of the program? ______________________________________________________________________________ 2. What happens after you clicked the left button of the mouse 10 times? ______________________________________________________________________________ 3. Try to code the given sample program below: Program Listing 7.1
.model small .data ESCkey = 1Bh GreetingMsg DB ChangeChar DB CharA DB LastMessage DB Xclick DW 0 Yclick DW 0 XCoordinate DW 0 YCoordinate DW 0

"Press Esc to quit", 0 "Click anywhere then character to change", 0 'a' "Press any key to continue", 0

displetter macro data pusha mov ah, 9 mov al, data mov bh, 0 mov bl, 03 mov cx, 0001 int 10h popa endm dispstring pusha mov mov mov mov lea int popa endm .386 .code main macro data ah, 13h al, 01 bh, 00 bl, 01h bp, data 10h

; this is the macro for ; displaying the letter ; at the screen

; this is the macro for ; displaying the string ; on the screen

PROC FAR mov ax, @data mov ds, ax mov es, ax ;Hide the text cursor and display the mouse call HideCursor call Clrscr mov dx, 0 call Gotoxy mov cx, 18 mov dx, 00 dispstring GreetingMsg call ShowMousePointer mov call dx, 0526h Gotoxy

9 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

displetter inc

charA charA

mov cx, 30 mov dx, 011Bh dispstring ChangeChar mov Xclick, 0026h mov Yclick, 0005h ; Loop: Check for left mouse ; button click, or for a keypress (Esc key). L1: call mov int jz mov int cmp je L2: jmp L1 ; no, continue the loop ; Hide the mouse, restore the text cursor, clear ; the screen, and display "Press any key to continue." quit: call call call lea mov call mov int mov int ENDP HideMousePointer ShowCursor Clrscr dx, LastMessage cx, 26 WriteString ah, 10h 16h ah, 4ch 21h PROC pusha mov ah, 2 mov bh, 0 int 10h popa ret Gotoxy Clrscr pusha mov mov mov mov int mov mov mov int popa ret Clrscr ENDP PROC ax, 0600h cx, 0 dx, 184Fh bh, 7 10h ah, 2 bh, 0 dx, 0 10h ENDP LeftButtonClick ah, 11h 16h L2 ah, 10h 16h al, ESCkey quit ; check for button click ; key pressed already? ; no, continue the loop ; remove key from buffer ; yes. Is it the ESC key? ; yes, quit the program

main Gotoxy

10 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

WriteString pusha mov mov int popa ret WriteString

PROC ah, 40h bx, 1 21h ENDP

HideCursor PROC ; Hide the text cursor by setting its top line ; value to an illegal value. mov int or mov int ret HideCursor ShowCursor mov int mov mov int ret ShowCursor ah, 3 10h ch, 30h ah, 1 10h ENDP PROC ah, 3 10h ah, 1 cx, 0607h 10h ENDP PROC ; hide mouse cursor ; get cursor size ; set cursor size ; default size ; get cursor size ; set upper row to illegal value ; set cursor size

HideMOusePointer push ax mov ax, 2 int 33h pop ax ret HideMousePointer ShowMousePointer pusha mov ax, 1 int 33h popa ret ShowMousePointer LeftButtonClick ; Check for the ; ; Receives: ; Returns: ; ; pusha mov ah, 0 mov al, 5 mov bx, 0 int 33h shr cx, 3 shr dx, 3

ENDP PROC ; make mouse cursor available

ENDP PROC most recent left mouse button press, BX = button number (0 = left, 1 = right, 2 = middle) BX = button press counter CX = X-coordinates DX = Y-coordinates ; get mouse status ; (button press information) ; specify the left button ; divide coordinates by 8

11 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

; Exit proc if the coordinates have not changed. cmp cx, Xcoordinate jne LBC3 cmp dx, Ycoordinate je LBC1 LBC3: mov mov cmp jne cmp je jmp LBC2: inc charA LBC1: mov mov mov int dx, 0526h ah, 2 bh, 0 10h Xcoordinate, cx Ycoordinate, dx cx, Xclick LBC1 dx, Yclick LBC2 LBC1

call ShowMousePointer displetter charA popa ret LeftButtonClick END main

ENDP

4. Discuss the results obtained. _______________________________________________________________________________________________________ _______________________________________________________________________________________________________ __ The character changes only after following this pattern: Click the character Click the position outside of the character. Keep repeating this pattern. 5. Why are these results obtained? _______________________________________________________________________________________________________ _______________________________________________________________________________________________________ __

7.4 PROGRAMMING EXERCISES

1. Create a mouse click counter, having two buttons shown in your console labeled Increase and
Decrease. Increment the counter if left button was clicked on the Increase button, and decrement it if right button was clicked on the Decrease button. Have a maximum of 100 and a minimum of 0 (in decimal) for your counter. Allow spacebar to exit the application. Implement the following procedure in just a single program: a. Getting Button Release Information b. Setting Horizontal and Vertical Limits c. Allowing third mouse button click (the middle/wheel button)

2.

7.5 REVIEW QUESTIONS


1. Indicate reasons why you need to divide the pixel values by 8 (or shr cx OR dx, 3).

12 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

2.

3.

_______________________________________________________________________________________________ _______________________________________________________________________________________________ __ What is mouse sensitivity? _______________________________________________________________________________________________ _______________________________________________________________________________________________ _ Suppose you want the mouse pointer to point to the middle of the character cell located at row 15, column 22 in text mode. What X and Y values will you have to pass to INT 33h Function 4? _______________________________________________________________________________________________ _______________________________________________________________________________________________ _

13 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

7.6 RESULTS AND OBSERVATIONS

14 ASSEMBLY LANGUAGE PROGRAMMING LABORATORY

Potrebbero piacerti anche