4.2: DOS INTERRUPT 21H Option 0AH inputting a data string from the keyboard. A means by which one can get keyboard data from & store it in a predefined data segment memory area. Register AH = 0AH. DX = offset address at which the string of data is stored. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
4.2: DOS INTERRUPT 21H Option 0AHinputting a data string from the keyboard• A means by which one can get keyboard data from &
store it in a predefined data segment memory area. – Register AH = 0AH.– DX = offset address at which the string of data is stored.
• Commonly referred to as a buffer area.
• DOS requires a buffer area be defined in the data segment.– The first byte specifies the size of the buffer. – The number of characters from the keyboard is in the
second byte.– Keyed-in data placed in the buffer starts at the third byte.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
4.2: DOS INTERRUPT 21H Option 0AHinputting a data string from the keyboard• Assuming the data entered through the keyboard
was "USA" <RETURN>, the contents of memory locations starting at offset 0010H would look like:
– 0010H = 06 DOS requires the size of the buffer here.– 0011H = 03 The keyboard was activated three times
(excluding the RETURN key) to key in letters U, S, and A.– 0012H = 55H ASCII hex value for letter U.– 0013H = 53H ASCII hex value for letter S.– 0014H = 41H ASCII hex value for letter A.– 0015H = 0DH ASCII hex value for CR. (carriage return)
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
4.2: DOS INTERRUPT 21H inputting more than buffer size• Entering more than six characters (five + the CR = 6)
will cause the computer to sound the speaker.– The contents of the buffer will look like this:
– Location 0015 has ASCII 20H for <SPACE>– Location 0016 has ASCII 61H for "a“.– Location 0017 has 0D for <RETURN> key. – The actual length is 05 at memory offset 0011H.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
4.2: DOS INTERRUPT 21H use of carriage return and line feed• In Program 4-2, the EQU statement is used to equate
CR (carriage return) with its ASCII value of 0DH, and LF (line feed) with its ASCII value of 0AH. – See pages 141 & 142
• Program 4-3 prompts the user to type in a name with a maximum of eight letters.– The program gets the length and prints it to the screen.– See page 143.
• Program 4-4 demonstrates many functions described in this chapter.– See pages 144 & 145.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
• There are applications in Assembly language programming where a group of instructions performs a task used repeatedly. – It does not make sense to rewrite them every time.
• Macros allow the programmer to write the task once only & invoke it whenever, wherever it is needed. – Reduces time to write code & reduce possibility of errors.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
comments in a macro• Two types of comments in the macro:– Listable; Nonlistable.
• Comments preceded by one semicolon (;) will show up in the ".lst" file when the program is assembled.– Those preceded by a double semicolon (;;) will not.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
comments in a macro• Three directives designed to make programs that use macros more readable, affecting the ".lst" file, with no effect on the ".obj" or ".exe" files: – .LALL (List ALL) will list all instructions/comments preceded by a single
semicolon in the ".lst" file. – .SALL (Suppress ALL) suppresses the listing of the macro body and the
comments. • Used to make the list file shorter and easier to read
– Will not eliminate any opcode from the object file.
– .XALL (eXecutable ALL) is used to list only the part of the macro that generates opcodes.
• The default listing directive.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
LOCAL directive and its use in macros• If a macro is expanded more than once, and there is a label in the label field of the body of the macro, these labels must be declared as LOCAL. – Otherwise, an assembler error would be generated when
the same label was encountered in two or more places.
• Rules which must be observed in the macro body:– 1. All labels in the label field must be declared LOCAL.– 2. LOCAL directive must be right after the MACRO directive. – 3. The LOCAL directive can be used to declare all names
and labels at once.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
INCLUDE directive• The INCLUDE directive allows a programmer to write macros, save them in a file, and later bring them into any file. – Used to bring this file into any ".asm" file, to allow
the program can call any of the macros as needed. • See Program 4 -7 on pages 155-157.
• In the list file of Program 4-7, the letter "C" in frontof the lines indicates that they are copied from another file and included in the present file.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
• The original IBM PC keyboard had 83 keys, in three major groupings:– 1. The standard typewriter keys.– 2. Ten function keys, F1 to F10.– 3. 15-key keypad.
• In later years, 101 key enhanced keyboards have become popular.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
• The same scan code is used for a given lowercase letter and its capital, and all keys with dual labels. – The keyboard shift status byte distinguishes the keys.
• Some INT 16H function calls provide the status byte in AL.
– For keyboard-motherboard, interaction IBM has provided INT 16H.
When a key is pressed, the OS stores its scan code in memory locations called a keyboard buffer, located inthe BIOS data area.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
5.1: INT 16H KEYBOARD PROGRAMMING checking a key press
• For a program to run tasks continuously while checking for a keypress requires use of INT 16H.– A BIOS interrupt used exclusively for the keyboard.
• To check a keypress, use INT 16H function AH = 01.
– If ZF = 0, there is a key press.– If ZF = 1, there is no key press.
• This function does not wait for the user to press a key—it simply checks to see if there is a key press. – If a character is available, it returns the scan code
in AH, and the ASCII code in AL.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
5.1: INT 16H KEYBOARD PROGRAMMINGother INT 16H functions
• INT 16H, AH = 10H(read a character) - the same as AH = 0, exceptthat it also accepts the additional keys on the IBM extended (enhanced) keyboard.
• INT 16H, AH = 11H(find if a character is available) - the same asAH = 1, except that it also accepts the additionalkeys on the IBM extended (enhanced) keyboard.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
5.2: MOUSE PROGRAMMING WITH INT 33H detecting the presence of a mouse
• Because the original IBM PC & DOS did not provide support for the mouse, interrupt INT 33H is not part of BIOS or DOS. – INT 33H is part of the mouse driver software installed
when the PC is booted.
• The first task of any INT 33H program should be to verify the presence of a mouse and the number of buttons it supports, using INT 33H function AX = 0. – On return from INT 33H, if AX = 0, no mouse is supported. – If AX = FFFFH, the mouse is supported and the number
of mouse buttons will be contained in register BX.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
5.2: MOUSE PROGRAMMING WITH INT 33H some mouse terminology
• The mouse pointer (or cursor) is the pointer on the screen indicating where the mouse is pointing at a given time. – In graphics mode it is an arrow.– In text mode, a flashing block.
• As the mouse is moved, the mouse cursor is moved.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
5.2: MOUSE PROGRAMMING WITH INT 33H some mouse terminology
• While movement of the mouse is measured in inches (or centimeters), movement of the mouse cursor on the screen is measured in units called mickeys. – Mickey units indicate mouse sensitivity.
• A mouse that can move the cursor 200 units forevery inch of mouse movement has a sensitivityof 200 mickeys. – In this case, one mickey represents 1/200 of an inch
on the screen. – Some mice have a sensitivity of 400 mickeys in contrast
to the commonly used 200 mickeys.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
5.2: MOUSE PROGRAMMING WITH INT 33H video resolution vs. mouse resolution
• When the video mode is set to text mode, the mouse will automatically adopt the same resolution of 640 × 200 for its horizontal/vertical coordinates. – When a program gets the mouse cursor position, values
are provided in pixels and must be divided by 8.• To get position in terms of character locations 0 to 79
(horizontal) and 0 to 24 (vertical) on the screen.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey
5.2: MOUSE PROGRAMMING WITH INT 33H the button press count program• Program 5-5 on pages 172 - 173 uses the AX = 05
function to monitor the number of times the left button is pressed and then displays the count. – It prompts the user to press the left button a number
of times. • When the user is ready to see how many times the button
was pressed, any key can be pressed.
The x86 PCAssembly Language, Design, and InterfacingBy Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey