INT 21H and INT 10H Programming and Macros

Similar documents
ELEC VIDEO BIOS ROUTINES

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

ORG ; TWO. Assembly Language Programming

Video processing The INT instruction enables program to interrupt its own processing. Use INT instruction to handle inputs and outputs

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Experiment 3 3 Basic Input Output

Intel Architecture Segment:Offset Memory Addressing

Lab 10 CST8214 Ian! D. Allen Fall 2007

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Topics Introduction to Microprocessors. Chapter 5 Macros and modules. What is macro? How to use macro? (I) How to use macro?

Assembly Language: g Part III. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

The registers(di,si) are automatically incremented or decremented depending on the value of the direction flag:

The statement above assumes that the PCMAC.INC file is in the current directory. The full path of the file can also be given:

Lab 3: Defining Data and Symbolic Constants

Experiment N o 1. 1 Introduction to Assembly Language Programming

Lecture 13: I/O I/O. Interrupts. How?

Lecture (09) x86 programming 8

Hardware and Software Architecture. Chapter 2

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

CC411: Introduction To Microprocessors

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

Experiment N o 1. Introduction to Assembly Language Programming

UNIT 4. Modular Programming

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 13: 16-Bit MS-DOS Programming

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

Experiment 8 8 Subroutine Handling Instructions and Macros

Microprocessors (A) DOS Services

Lab 5: Input/Output using a Library of Procedures

CPU. IBM PC and compatible Memory Structure

2003 LXI H, 42F2H ; this instruction store 42F2 in to the HL pair POP H ; store data from top of the stack to HL pair

Arithmetic and Logic Instructions And Programs

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

Experiment N o 8. String Handling Instructions

CP/M-86 Compatibility Guide For CP/M-80 Users

ELEG3924 Microprocessor

Programming in Module. Near Call

PESIT Bangalore South Campus

Week /8086 Microprocessor Programming II

8086 ALP TOOLS (CH 2) CHAPTER 2

EXPERIMENT NINE DEVELOPING MACRO SEQUENCES

LABORATORY 1: EXPLORING THE SOFTWARE ARCHITECTURE OF THE MICROPROCESSOR

Chapter 3: Addressing Modes

Assembly Language Each statement in an assembly language program consists of four parts or fields.

EEM336 Microprocessors I. Data Movement Instructions

INTRODUCTION. NOTE Some symbols used in this manual CL = Click Left CR = Click Right DCL = Double Click Left = Enter. Page 1

Assembly Language for Intel-Based Computers, 4 th Edition

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Lab 2: Introduction to Assembly Language Programming

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

PD26xx/PD23xx/PD28xx Series Command Detail Manual

Philadelphia University Student Name: Student Number:

CS401 Assembly Language Solved MCQS From Midterm Papers

Mr. Sapan Naik 1. Babu Madhav Institute of Information Technology, UTU

ALT-Assembly Language Tutorial

Lecture 6. Assembler Directives

Midterm Exam #2 Answer Key

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

Memory Organization. 27 December 2016 Pramod Ghimire. Slide 1 of 21

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Experiment N o 3 Segmentation and Addressing Modes

Assembly Language Programming

Q. State and Explain steps involved in program development. [w-08, w-10, s-12, w-11]

Description of the Simulator

================== CEDRIC VERSION 2.1 By M.J.RANDALL ================== INTRODUCTION

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Module 3 Instruction Set Architecture (ISA)

Come and join us at WebLyceum

Tutorial Letter 103/3/2012 Computer Organization COS2621 Semesters 1 & 2

The 8051 Microcontroller and Embedded Systems

ELEC 242 Time Delay Procedure

Computer Architecture and System Software Lecture 06: Assembly Language Programming

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

ELEC 242 Using Library Procedures

SHEET-2 ANSWERS. [1] Rewrite Program 2-3 to transfer one word at a time instead of one byte.

Assembly Language Lab # 11 Kyboard input with int 16 & Macros

db "Please enter up to 256 characters (press Enter Key to finish): ",0dh,0ah,'$'

DEC HEX ACTION EXTRA DESCRIPTION

Assignment 3. Problem Definition:

IS-DEV KIT-9 User Manual

Lecture (05) x86 programming 4

16-bit MS-DOS and BIOS Programming

Assembly Language for Intel-Based Computers, 4 th Edition

CSE 505 Lecture 8: Introduction to Assembly Language

MOPS/386A (P389) MOPS/MZ and MOPSlcdMZ (PMZ1) MOPS/520 (P489) DOT Matrix Display on PC/104 Products

EC-333 Microprocessor and Interfacing Techniques

CMSC 412 Project 1: Keyboard and Screen Drivers

Cross Assembly and Program Development

Proposed Common Configuration Method

DOS INT 21h - DOS Function Codes

IS-Dev Kit-8 User Manual

Operating Systems. Project #2: System Calls

EC-333 Microprocessor and Interfacing Techniques

FALSIM. FALSIM is the name of the software application which consists of the FALCON-A assembler and the FALCON-A simulator. It runs under Windows XP.

Transcription:

Dec Hex Bin 4 4 00000100 ORG ; FOUR INT 21H and INT 10H Programming and Macros

OBJECTIVES this chapter enables the student to: Use INT 10H function calls to: Clear the screen. Set the cursor position. Write characters to the screen in text mode. Draw lines on the screen in graphics mode. Change the video mode. Use INT 21H function calls to: Input characters from the keyboard. Output characters to the screen. Input or output strings.

OBJECTIVES this chapter enables the student to: (cont) Use the LABEL directive to set up structured data items. Code Assembly language instructions to define and invoke macros. Explain how macros are expanded by the assembler. Use the LOCAL directive to define local variables within macros. Use the INCLUDE directive to retrieve macros from other files.

4.0: INT 21H and 10H The INT instruction is somewhat like a FAR call. Saves CS:IP and the flags on the stack and goes to the subroutine associated with that interrupt. In x86 processors, 256 interrupts, numbered 00 to FF. INT 10H and INT 21H are the most widely used with various functions selected by the value in the AH register.

4.1: BIOS INT 10H PROGRAMMING INT 10H subroutines are burned into the ROM BIOS. Used to communicate with the computer's screen video. Manipulation of screen text/graphics can be done via INT 10H. Among the functions associated with INT 10H are changing character or background color, clearing the screen, and changing the location of the cursor. Chosen by putting a specific value in register AH.

4.1: BIOS INT 10H PROGRAMMING monitor screen in text mode The monitor screen in the x86 PC is divided into 80 columns and 25 rows in normal text mode. Columns are numbered from 0 to 79. Rows are numbered 0 to 24. The top left corner has been assigned 00,00, the top right 00,79. Bottom left is 24,00, bottom right 24,79. Figure 4-1 Cursor Locations (row, column)

4.1: BIOS INT 10H PROGRAMMING screen clearing with INT 10H function 06H To clear the screen using INT 10H, these registers must contain certain values before INT 10H is called: AH = 06, AL = 00, BH = 07, CX = 0000, DH = 24, DL = 79. Option AH = 06 calls the scroll function, to scroll upward. CH & CL registers hold starting row & column. DH & DL registers hold ending row & column.

4.1: BIOS INT 10H PROGRAMMING setting the cursor to a specific location INT 10H function AH = 02 will change the position of the cursor to any location. Desired position is identified by row/column values in DX. Where DH = row and DL = column. Video RAM can have multiple pages of text. When AH = 02, page zero is chosen by making BH = 00. After INT 10H (or INT 21H) has executed, registers not used by the interrupt remain unchanged.

4.1: BIOS INT 10H PROGRAMMING setting the cursor to a specific location Example 4-1 demonstrates setting the cursor to a specific location.

4.1: BIOS INT 10H PROGRAMMING get current cursor position In text mode, determine where the cursor is located at any time by executing the following: After execution of the program, registers DH & DL will have current row and column positions. CX provides information about the shape of the cursor. In text mode, page 00 is chosen for the currently viewed page.

4.1: BIOS INT 10H PROGRAMMING changing the video mode To change the video mode, use INT 10H with AH = 00 and AL = video mode.

4.1: BIOS INT 10H PROGRAMMING attribute byte in monochrome monitors An attribute associated with each character on the screen provides information to the video circuitry. Character (foreground) & background color/intensity. The attribute byte for each character on the monochrome monitor is limited. Actual character displayed For foreground only.

4.1: BIOS INT 10H PROGRAMMING attribute byte in monochrome monitors See the entire example on page 134 of your textbook. Possible variations of attributes in Fig. 4-2.

4.1: BIOS INT 10H PROGRAMMING attribute byte in CGA text mode CGA mode is the common denominator for all color monitors, as S all color monitors & video circuitry are upwardly compatible, CGA attribute byte bit definition is as shown: Figure 4-3 CGA Attribute Byte

4.1: BIOS INT 10H PROGRAMMING attribute byte in CGA text mode The background can take eight different colors by combining the prime colors red, blue, and green. The foreground can be any of 16 different colors by combining red, blue, green, and intensity Example 4-4 shows the use of the attribute byte in CGA mode.

4.1: BIOS INT 10H PROGRAMMING attribute byte in CGA text mode Some possible CGA colors and variations.

4.1: BIOS INT 10H PROGRAMMING graphics: pixel resolution & color In text mode, the screen is viewed as a matrix of rows and columns of characters. In graphics mode, a matrix of horizontal & vertical pixels. Number of pixels depends on monitor resolution & video board. Two facts associated with every pixel on the screen must be stored in the video RAM: Location of the pixel, and Attributes. (color and intensity) The higher the number of pixels and colors, the larger the amount of memory that is needed to store them Memory requirements go up with resolution & number of colors. CGA mode can have a maximum of 16K bytes of video memory due to its inherent design structure.

4.1: BIOS INT 10H PROGRAMMING graphics: modes Text mode of 80 25 characters. A total of 2K (80 25 = 2000) for characters, plus 2K for attributes, as each character has one attribute byte. Each screen (frame) takes 4K, which results in CGA supporting a total of four pages of data, where each page represents one full screen. In this mode, 16 colors are supported. To select this mode, use AL = 03 for mode selection in INT 10H option AH = 00.

4.1: BIOS INT 10H PROGRAMMING graphics: modes Graphics mode of 320 200. (medium resolution) 64,000 pixels. (320 columns 200 rows = 64,000) Dividing total video RAM of 128K bits (16K 8 bits = 128K) by 64,000 pixels gives 2 bits for the color of each pixel. 2 bits give four possibilities, thus 320 200 resolution CGA can support no more than 4 colors. To select this mode, use AL = 04.

4.1: BIOS INT 10H PROGRAMMING graphics: modes Graphics resolution of 640 200. (high resolution) 128,000 pixels. (200 640 = 128,000) Dividing gives 1 bit (128,000/128,000 = 1) for color, which can can be on (white) or off (black). 640 200 high-resolution CGA can support only black and white. To select this mode, use AL = 06. With a fixed amount of video RAM, the number of supported colors decreases as resolution increases. To create more colors in video boards there must be memory available to store the extra colors.

4.1: BIOS INT 10H PROGRAMMING INT 10H and pixel programming To address a single pixel on the screen, use INT 10H with AH = 0CH. The X (column) and Y (row) coordinates of the pixel must be known, and vary, depending on monitor resolution. Registers are CX = the column point (the X coordinate) and DX = the row point. (Y coordinate) To turn the pixel on/off, AL=1 or AL=0 for black and white. The value of AL can be modified for various colors. If the display mode supports more than one page, BH = page number.

4.1: BIOS INT 10H PROGRAMMING drawing lines in graphics mode To draw a horizontal line, choose row/column values to point to the beginning of the line and increment the column until it reaches the end of the line. To draw a vertical line, increment the vertical value held by the DX register, and keep CX constant. Linear equation y = mx + b can be used for any line.

4.1: BIOS INT 10H PROGRAMMING drawing lines in graphics mode Drawing a horizontal line

4.2: DOS INTERRUPT 21H In previous chapters, a fixed set of data was defined in the data segment & results viewed in a memory dump. This section uses information inputted from the keyboard, and displayed on the screen. A much more dynamic way of processing information. When the OS is loaded, INT 21H can be invoked to perform some extremely useful functions. Commonly referred to as DOS INT 21H function calls. In contrast to BIOS-ROM based INT 10H.

4.2: DOS INTERRUPT 21H Option 09 outputting a data string the monitor INT 21H can send a set of ASCII data to the monitor. Set AH = 09 and DX = offset address of the ASCII data. Displays ASCII data string pointed at by DX until it encounters the dollar sign "$". The data segment and code segment, to display the message "The earth is but one country" :

4.2: DOS INTERRUPT 21H Option 02 outputting a single character To output only a single character, 02 is put in AH, and DL is loaded with the character to be displayed. The following displays the letter "J" : This option can also be used to display '$' on the monitor as the string display option (option 09) will not display '$.

4.2: DOS INTERRUPT 21H Option 01 inputting a single character, with echo This functions waits until a character is input from the keyboard, then echoes it to the monitor. After the interrupt, the input character will be in AL.

4.2: DOS INTERRUPT 21H Option 01 inputting a single character, with echo Program 4-1 combines INT 10H and INT 21H. The program does the following: (1) Clears the screen. (2) Sets the cursor to the center of the screen. (3) Displays the message "This is a test of the display routine". See the entire program listing on page 139 of your textbook.

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. 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.

4.2: DOS INTERRUPT 21H Option 0AH inputting a data string from the keyboard This program accepts up to six characters from the keyboard, including the return (carriage return) key. Six buffer locations were reserved, and filled with FFH. Memory contents of offset 0010H: The PC won t exit INT 21H until it encounters a RETURN.

4.2: DOS INTERRUPT 21H Option 0AH inputting 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)

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.

4.2: DOS INTERRUPT 21H inputting more than buffer size If only the CR key is activated & no other character: 0AH is placed in memory 0020H. 0021H is for the count. 0022H IS the first location to have data that was entered. CR is not included in the count. If only the <RETURN> key is activated, 0022H has 0DH, the hex code for CR. The actual number of characters entered is 0 at location 0021.

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.

4.2: DOS INTERRUPT 21H Option 07 keyboard input without echo Option 07 requires the user to enter a single character, which is not displayed (or echoed) on the screen. The PC waits until a single character is entered and provides the character in AL.

4.2: DOS INTERRUPT 21H using LABEL to define a string buffer The LABEL directive can be used in the data segment to assign multiple names to data. Used to assign the same offset address to two names. The attribute can be: BYTE; WORD; DWORD; FWORD; QWORD; TBYTE. In the following: The offset address assigned to JOE is the same offset address for TOM since the LABEL directive does not occupy any memory space.

4.2: DOS INTERRUPT 21H using LABEL to define a string buffer Use this directive to define a buffer area for the string keyboard input: In the code segment the data can be accessed by name as follows:

4.3: WHAT IS A MACRO, AND HOW IS IT USED? 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.

4.3: WHAT IS A MACRO, AND HOW IS IT USED? MACRO definition Every macro definition must have three parts: The MACRO directive indicates the beginning of the macro definition, ENDM directive signals the end. In between is the body of the macro. The name must be unique and must follow Assembly language naming conventions. Dummies are names, parameters, or registers that are mentioned in the body of the macro. The macro can be invoked (or called) by its name, and appropriate values substituted for dummy parameters.

4.3: WHAT IS A MACRO, AND HOW IS IT USED? MACRO definition A macro for displaying a string of data using the widely used function 09 of INT 21H:

4.3: WHAT IS A MACRO, AND HOW IS IT USED? MACRO definition In the following code segment, the macro can be invoked by its name with the user's actual data: Instruction "STRING MESSAGE1" invokes the macro. The assembler expands the macro by providing the following code in the.lst file: The (1) indicates that the code is from the macro. Earlier versions of MASM, used a plus sign (+).

4.3: WHAT IS A MACRO, AND HOW IS IT USED? 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.

4.3: WHAT IS A MACRO, AND HOW IS IT USED? 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.

4.3: WHAT IS A MACRO, AND HOW IS IT USED? 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.

4.3: WHAT IS A MACRO, AND HOW IS IT USED? LOCAL directive and its use in macros In example 4-7, the "BACK" label is defined as LOCAL right after the MACRO directive.

4.3: WHAT IS A MACRO, AND HOW IS IT USED? 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 front of the lines indicates that they are copied from another file and included in the present file.

Dec Hex Bin 4 4 00000100 ENDS ; FOUR