8. MACROS, Modules, and Mouse



Similar documents
How To Use A Computer With A Screen On It (For A Powerbook)

Faculty of Engineering Student Number:

Character Translation Methods

A Tiny Guide to Programming in 32-bit x86 Assembly Language

Mouse Programming Mouse Interrupts Useful Mouse functions Mouselib.h Mouselib.c

Instructions for Importing (migrating) Data

Complete 8086 instruction set

King Fahd University of Petroleum and Minerals. College of Computer Science and Engineering. Computer Engineering Department COE 205

MS Access Lab 2. Topic: Tables

INTRODUCTION TO PROGRAMMING THE 8086

8 CREATING FORM WITH FORM WIZARD AND FORM DESIGNER

First Bytes Programming Lab 2

13-1. This chapter explains how to use different objects.

Memory Management Simulation Interactive Lab

MS-DOS, PC-BIOS, and File I/O Chapter 13

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

CNCTRAIN OVERVIEW CNC Simulation Systems

Microsoft Access Basics

Microsoft Access 2010 handout

The Hexadecimal Number System and Memory Addressing

Introduction. Why Use ODBC? Setting Up an ODBC Data Source. Stat/Math - Getting Started Using ODBC with SAS and SPSS

by Kip Irvine. Last update: 12/11/2003

Computer Organization and Assembly Language

MyOra 3.5. User Guide. SQL Tool for Oracle. Kris Murthy

2150 North First Street, Suite 440 Phone: (408) San Jose, CA FAX: (408)

Operating Systems. and Windows

Excel Level Two. Introduction. Contents. Exploring Formulas. Entering Formulas

0 Introduction to Data Analysis Using an Excel Spreadsheet

Drawing a histogram using Excel

Outline. Lecture 3. Basics. Logical vs. physical memory physical memory. x86 byte ordering

PC Assembly Language. Paul A. Carter

64-Bit NASM Notes. Invoking 64-Bit NASM

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Using SQL Server Management Studio

Real Time Monitor. A Real-Time Windows Operator Interface. DDE Compliant. (for remote data display)

This activity will show you how to draw graphs of algebraic functions in Excel.

for ECM Titanium) This guide contains a complete explanation of the Driver Maker plug-in, an add-on developed for

X86-64 Architecture Guide

Getting Started with IntelleView POS Administrator Software

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

Tutorial for Tracker and Supporting Software By David Chandler

Introduction to the TI-Nspire CX

Assembly Language Tutorial

Switching from PC SAS to SAS Enterprise Guide Zhengxin (Cindy) Yang, inventiv Health Clinical, Princeton, NJ

RACEAIR REMOTE PAGER SYSTEM

2. More Use of the Mouse in Windows 7

The x86 PC: Assembly Language, Design, and Interfacing 5 th Edition

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

User Tutorial on Changing Frame Size, Window Size, and Screen Resolution for The Original Version of The Cancer-Rates.Info/NJ Application

Pay Invoice User Instructions

The goal is to program the PLC and HMI to count with the following behaviors:

REpsych. : psycholigical warfare in reverse engineering. def con 2015 // domas

5. You will need to confirm your registration, by entering a unique code displayed on the page and click Confirm Signup

Have you seen the new TAMUG websites?

Quick Start Tutorial. Using the TASKING* Software Development Tools with the Intel 8x930 Family Evaluation Board

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc.

Employee Appointment Books. User s Manual

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Creating a Database in Access

Intermediate PowerPoint

Basic Operation and Function of the MSD Pro Data Plus. Best viewed in printed form. Click on File>Print.

CE 490 Transportation Engineering Network Analysis

Programming in Access VBA

Document Cycle Tracking Service User Guide

Beginner s Matlab Tutorial

Writing a Simple Operating System from Scratch

TIn 1: Lecture 3: Lernziele. Lecture 3 The Belly of the Architect. Basic internal components of the Pointers and data storage in memory

Model 288B Charge Plate Graphing Software Operators Guide

Using Heap Allocation in Intel Assembly Language

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

Hypercosm. Studio.

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Systems Design & Programming Data Movement Instructions. Intel Assembly

While Loops and Animations

Ethereal: Getting Started

Microsoft Office Access 2007 Basics

Developing Website Using Tools

Tutorial 13: Object Animation

NJCU WEBSITE TRAINING MANUAL

Installation and Demonstration Manual

Microsoft Access 2010 Part 1: Introduction to Access

Introduction to Microsoft Access 2003

In this session, we will explain some of the basics of word processing. 1. Start Microsoft Word 11. Edit the Document cut & move

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

Athena Knowledge Base

General Precautions The user must operate each product according to the performance specifications described in the operation manuals.

Getting Started with Excel Table of Contents

DEG Web User Guide State of Michigan Data Exchange Gateway Web

Appendix C: Keyboard Scan Codes

Hermes.Net IVR Designer Page 2 36

Help. Contents Back >>

Intellect Platform - The Workflow Engine Basic HelpDesk Troubleticket System - A102

Intellect Platform - Tables and Templates Basic Document Management System - A101

Compiler Construction

User s Manual CAREpoint EMS Workstation D-Scribe Reporting System

Transcription:

8. MACROS, Modules, and Mouse Background Macros, Modules and the Mouse is a combination of concepts that will introduce you to modular programming while learning how to interface with the mouse. Macros allow us to use a sequence of instructions over and over without retyping them. Modules assist us in breaking the program up into many pieces that can stand alone. Objectives Be able to: Pre-Lab A. Develop Macro sequences for common programming tasks. B. Develop modules C. Pass parameters between modules D. Access the mouse. E. Include the mouse in MACROS. Demonstrate the program from Applying what you have learned section of the previous lab. Describe what occurs internally in x86 microprocessors when the call and ret instructions are executed. Be sure to include any registers or memory that may be modified. Lab A. Using MACROS MACROS prevent programmers from having to retype the same instruction over and over. The MACRO is stored in-line in the program source code file so it does not require accesses to a disk or memory. However, the instructions for the MACROS may be stored on a disk and referenced or included in multiple programs. The MACRO definition has 3 parts. name MACRO variable1, variable2, variable3......... The MACRO statement identifies the beginning and the statement identifies the end of the MACRO. The variables that are carried into the MACRO are listed after the MACRO statement. The instructions are included between MACRO and.

How would you change Example 6.2 (lab #6) to a MACRO? How would you use the MACRO to clear only a portion of the screen? Example 8.1 CLEAR_PART MACRO START, STOP ;This MACRO clears a portion of the screen ;;Uses option 06 of INT 10H MOV AX, 0600H ;scroll screen function MOV BH, 07 ;normal attribute MOV CX, START ;start at word stored in START MOV DX, STOP INT 10H ;end at word stored in STOP The values stored in the variables, START and STOP are word values for this MACRO. For example, to clear the upper left corner of the screen, START=0000H and STOP=0C27H. Thus, the MACRO will be called from the main routine as such: CLEAR_PART 0000,0C27H ;clear from 00,00 to 0CH,27H The lines in the MACRO that contain the single semicolon (;) is a comment that will appear on the in the.lst file. The comment with the double semicolon (;;) will not appear in the MASM list file. In the MASM file, the MACROS are listed after the PAGE segment but before the STACK segment. How would you change the program written in Applying what you have learned of lab 6 using MACROS? Example 8.2 demonstrate the use of data segments in a MACRO. Example 8.2 DISPLAY MACRO STRING ;This MACRO displays a string of data ;;DX= address of the string uses option 9 of INT 21H MOV AH,09 ;option 9 MOV DX, Offset STRING INT 21H ;----- STSEG SEGMENT DB 64 DUP (?) STSEG ENDS ;-----

DTSEG SEGMENT NAME1 DB My name, $ NAME2 DB is James, $ Class1 DB I am, $ Class2 DB a Jr, $ DTSEG ENDS ;----- CDSEG SEGMENT MAIN PROC FAR ASSUME CS:CDSEG;DS:DTSEG;SS:STSEG MOV AX, DTSEG MOV DS,AX.LALL CLEAR_PART 0000,184FH DISPLAY NAME1 DISPLAY NAME2.XALL DISPLAY CLASS1.SALL DISPLAY CLASS2 MOV AH,4CH INT 21H MAIN ENDP CDSEG ENDS END MAIN How can you improve the above program? Write a MACRO that will place the cursor in a position for the next string using your improved method. What is the effect of the.lall,.xall, and.sall on the list file? MACROS can also contain local variables. The variables are usually used as labels. It is very important to define any variables used inside the MACRO as LOCAL. For example, the DISPLAY MACRO may be changed to exit upon receipt of a certain character. Example 8.3 DISPLAY MACRO Charact LOCAL EXIT, BEGIN BEGIN:

EXIT: MOV AH,2 MOV DL, Charact INT 21H JNE EXIT OR AL, 0 JE BEGIN MOV BL,00 ;store and display 00 upon exit DISPLAY BL INT 21H When using the same MACRO in several programs, we may include the MACROs in a separate file. Suppose we store the MACROs in a file called macro.mac, we can use the INCLUDE directive in order to access the MACRO in our program. We would use the following syntax. CDSEG SEGMENT code... ASSUME CS:CODE INCLUDE MACRO.MAC B. Using the Mouse The mouse has become extremely popular in the last few years. In assembly language, we use INT 33H to access the mouse. INT 33H has a different nomenclature than INT 16H, INT 10H, and INT 21H. In INT 33H, AL is used to set various modes of the function and AH is set to zero. Upon return of INT 33H is AX=0, then no mouse is supported. Therefore, our first MACRO will be used to determine whether the mouse is supported. Also upon return, BX holds the number of buttons on the mouse. Example 8.4 CHECK_MOUSE MACRO MOV AX,0 INT 33H CMP AX,0 JE EXIT The AX=01 function of INT 33H enables (displays) the mouse cursor and the AX=02 function disables the mouse cursor. Example 8.5 shows a MACRO to enable the mouse. It is important to disable the mouse prior to updating graphical or video information.

Example 8.5 MOUSE_ON MACRO MOV AX, 01 INT 33H We are often required to know the position of the mouse cursor. The mouse adopts the resolution of the video; however, the cursor uses 8x8 pixels. Therefore, when a program gets a mouse cursor position, the values are provided in pixels and must be divided by eight (8) to get the mouse cursor position in terms of the character locations 00,00 to 18,4FH. INT 33H option 3 gets the current position of the mouse. Upon return from INT 33H, CX contains the horizontal position and DX contains the vertical position. Remember that the positions are in pixels. You may need a routine to convert the pixels to characters for video mode. BX contains the button status. The LSB (D0) contains the left button status, D1 contains the right button status, and D2 (3rd bit) contains the center button status. The status is 1 if the button is down and 0 if its up. Option 5 returns the button status and the position of the position of the last button pressed. When calling INT 33H, AX=5 to select option 5. BX should contain the button number being tested. BX=0 indicates the left button, BX=1 indicates the right button. If a third button is present, BX=4 indicates the middle button. On return from option 5, AX shows the status of the buttons. The LSB (D0) is 1 for left button, D1 is 1 for the right button and D3 is 1 if the middle button was pressed. BX contains the number of times that the button was pressed. DX contains the row position of the click, and CX contains the column position of the click. Again, the values in CX and DX are in pixels and must be converted to characters. Option 6 provides information concerning button release. It operates the same as option 5 except BX contains the button release count. What is the difference in option 3 and option 5? Example 8.6 is a MACRO for detecting the number of times that the left button was pressed. How may we change the MACRO to use for various buttons? Example 8.6 LEFT_BUTN MACRO MOV AX,05 MOV BX,0 INT 33H Incorporate the MACRO into a program that displays which button is pressed and how many times. Turn the mouse cursor off prior to displaying text. Don t forget to turn it back on.

How would you detect whether a red square in the center of the screen has been clicked? Write a program that answers the question above. If the red square is clicked, clear the screen, and exit the program. Otherwise, display You missed the square. on the screen. Use MACROS to 1) detect mouse click 2) display words on the screen 3) draw the square 4) clear the screen. Remember to convert from pixels to characters for the mouse position. C. Using Modules MACROS allow us to use routines by calling the name of the routine in line in the main program. There are other methods of modular programming. One other method is subroutines. Subroutines are typically larger than MACROs. The PROC directive discussed in Lab 3 is also used for subroutines. Subroutines are also declared as FAR, NEAR, PROC. To use a subroutine in the main procedure, we must define the subroutine prior to its use in the code segment. We use the EXTRN directive to notify the assembler that the routine name following EXTRN is in another module. EXTRN name:type Name can be data where type would be either byte, word, dword, fword, qword, or tbyte. Or name can be a subroutine where type would be NEAR, FAR, or PROC. Any variable that is declared as EXTRN in one module must be linked to a module that declares the variable as PUBLIC. PUBLIC name The subroutines may be in separate files or the same file. The format for a subroutine is as follows. Example 8.7 CDSEG SUBMOD SUBMOD CDSEG PUBLC SUBMOD SEGMENT PROC FAR ASSUME CS:CDSEG... RET ENDP ENDS END ;return to the calling program Modules are linked using the link command at the MS-DOS prompt or selecting LINK option in MASM. To link at the MS-DOS prompt, c:> link proc.obj + submod.obj + submod2.obj where proc.obj has the MAIN PROC, and SUBMOD and SUBMOD2 are declared as EXTRN in main. We use the CALL statement to access the subroutines for example, to call SUBMOD, we use the following statement. CALL SUBMOD When using subroutines, it is often useful to store the registers on the stack using the PUSH at the beginning of the routine and using POP at the end.

What is the difference between a MACRO and a subroutine? Write a subroutine that will convert pixel values to characters upon return from option 3 of INT 33H. Do you remember SHR? How can you use it in the subroutine above? Lab Report A. Describing What You Learned Answer all of the Think about it questions above B. Applying what you have learned Be prepared to demonstrate any of the programs written for the various "Think about it" questions above..