0% found this document useful (0 votes)
311 views

Assembly Introduction To Screen and Keyboard Processing

The document discusses screen and keyboard processing using INT 10h and INT 21h BIOS interrupts. It provides examples of setting the cursor position and clearing the screen using INT 10h function 02h and 06h. It also gives examples of accepting keyboard input using INT 21h function 0Ah and displaying text on screen using INT 21h functions 02h, 09h, and 40h. File handles are described for redirecting input/output. Hands-on examples are provided to practice using the debugger.

Uploaded by

Reynel Isla Albo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
311 views

Assembly Introduction To Screen and Keyboard Processing

The document discusses screen and keyboard processing using INT 10h and INT 21h BIOS interrupts. It provides examples of setting the cursor position and clearing the screen using INT 10h function 02h and 06h. It also gives examples of accepting keyboard input using INT 21h function 0Ah and displaying text on screen using INT 21h functions 02h, 09h, and 40h. File handles are described for redirecting input/output. Hands-on examples are provided to practice using the debugger.

Uploaded by

Reynel Isla Albo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Introduction to Screen and Keyboard Processing

The INT (Interrupt)


 Handles input and output for most purposes.
 Int 10h is a low level BIOS operations that transfer control directly to BIOS.
 Int 21h provides an interrupt service for more complex operations and transfer control to DOS.

Functions Used by Screen and Keyboard Processing

INT 10h Functions INT 21h Functions


02h Set Cursor 02h Display character on screen
06h Scroll screen 09h Display string on screen
0Ah Input from keyboard
3Fh Input from keyboard
40h Display on screen

The Screen
 A typical video monitor has 25 rows (numbered 0 to 24) and 80 columns (numbered 0 to 79). The rows
and columns provide a grid of addressable locations at any one of which the cursor can be set.

Examples:
Screen Location Decimal Hexadecimal
Row Col Row Col
Upper left corner 00 00 00h 00h
Upper right cornet 00 79 00h 4fh
Center of screen 12 34/40 0ch 27h/28h
Lower left corner 24 00 18h 00h
Lower right corner 24 79 18h 4fh

Setting The Cursor


 Setting the cursor is a common requirement for text mode, because its position determines where the
next character is to display.
 INT 10h is the BIOS operation for screen handling, and function 02h in the AH tells the operation to set
the cursor.
 Load the require page or screen number, normally 0, in the BH register, the row in the DH, and the
column in the DL.
 The contents of the other registers are not important.

Ex.
mov ah,02h ;Request set cursor
mov bh,00 ;Page number 0
mov dh,08 ;Row 8
mov dl,15 ;Column 15
int 10h ; Call interrupt service

Clearing the Screen


 INT 10h function 06h handles screen clearing or scrolling
1
 Register settings:
o AH = function 06h
o AL = number of line to scroll, or 00h for the full screen
o BH = attribute value (color, reverse video, blinking)
o CX = starting row : column
o DX = ending row : column
 The CX and DX together define the screen area or window to be scrolled, and the AL provides the
number of lines to be scrolled up.

Ex.
mov ah,0600h ;Ah=06 (scroll), Al = 00 (full screen)
mov bh,71h ;White background (7), blue foreground (1)
mov cx,0000h ;Upper left row: column
mov dx,184fh ;Lower right row: column
int 10h

INT 21h Function 0Ah for Keyboard Input


 INT 21h function 0Ah for accepting data from the keyboard is particularly powerful.
 The input area for keyed in characters requires parameter list containing specified fields that the INT
operation is to process.
 The operation needs to know the maximum length of the input data.
 The purpose is to prevent users from keying in too many characters; the operation sounds the speaker
and does not accept additional characters.
 The operation delivers to the parameter list the number of bytes actually entered.
o Elements of a Parameter list:
 The first entry provides the name of the parameter list in the form LABEL Byte. LABEL
is a directive with the type attribute of BYTE, which simply causes alignment on a byte
boundary. Because that’s the normal alignment, the assembler does not advance its
location counter. The use of LABEL enables you to assign a name to the parameter list.
 The first byte of the parameter list contains your limit for the maximum number of input
characters. The minimum is 0 and, because this is a 1-byte field, the maximum is FFH, or
255.
 The second byte is for the operation to store the actual number of characters typed as a
binary value.
 The third byte begins a field that is to contain the typed characters, from left to right.

Ex.
Paralst Label Byte
Maxlen db 20
Actlen db ?
Kbdata db 20 DUP (‘ ‘)

Request input :
Mov ah,0ah ;request keyboard input
Lea dx,paralst ;load address of parameter list
Int 21h ;call interrupt service

Clearing the Enter Character


 You can use input characters for various purposes, such as printing on a report, storing in a table, or
writing on disk.

2
Ex. ACTLEN contains 11, then the enter character is at KBNAME+11.
Mov bx, actlen
Mov kbname[bx],20h

Clearing the Input Area


 Each character keyed in replaces the previous contents in the input area and remain hter until other
characters replace them.

Ex.
Mov cx,20
Mov si, 00
Again:
Mov kbname[si],20h
Inc si
Loop again

 Instead of the SI register, you could use DI or BC.


 If the routing moves a word of two blanks, it would require only 10 loops.
 However, because KBNAME is defined as DB (byte), use WORD and PTR (pointer) operand to
override its length.
Ex.
Mov cx, 10
Lea si, kbname
Again:
Mov word ptr[si], 2020h
Inc si
Inc si
Loop again
Using Control Characters in a Screen Display
 One way to make more effective use of displays is to use the Carriage Return, Line Feed, and Tab
control characters.
Control Characters Dec Hex Effect on Cursor
Carriage Return 13 0dh Resets to left position of screen
Line Feed 10 0ah Advances to next line
Tab 09 09h Advances to next tab stop

Ex.

Reptitle db 09,’Xpdotnet Annual Report’,13,10,’$’


……
Mov ah,09h
Lea dx, retitle
Int 21h

 Using EQU to redefine the control characters may make a program more readable:

Ex.
CR EQU 13
LF EQU 10
3
TAB EQU 09
Reptitle db TAB,’Xpdotnet Annual Report’,CR,LF,’$’

Int 21h Function 02h for Screen Display


 INT 21h function 02h use for displaying single character.
 Load in the DL the character that is to display at the current cursor position, and request INT 21h.
 The Tab, Carriage Return, and Line Feed act normally, and the operation automatically advances the
cursor.

Ex.
Cotitle db ‘xpdotnet Computer Services’, 13, 10, ‘S’
…….
Mov ah,02h
Mov cx,28
Lea di,Cotitle
Again:
Mov dl,[di]
Int 21h
Inc di
Loop again

FILE HANDLES
 A file handle is simply a number that refers to a specific device.
o File Handle Presets:

Handle Device
00 Input, normally keyboard, but may be redirected
01 Output, normally display, but may be redirected
02 Error output, display, may not be redirected
03 Auxiliary device (AUX)
04 Printer (LPT1 or PRN)

Int 21h Function 40h for Screen Display


 INT 21h function 40h uses file handles to request display operations.
o Registers settings:
 AH = Function 40h
 BX = File handle 01
 CX = Number of characters to display
 DX = Address of the display area
 A successful INT operation delivers to the AX the number of bytes written and clears the carry flag.

Ex.
Cotitle db ‘xpdotnet Computer Services’, 13, 10, ‘S’
…….
Mov ah,40h
Mov bx,01
Mov cx,28
Lea dx,Cotitle

4
Int 21h

Hands on Exercise using Debug.

Mov ah,40
Mov bx,0a
Mov cx,xx (length of your name)
Mov dx,10e
Int 21
Nop
Db ‘x-----------------x’ (insert your name here)

INT 21h Function 3fh for Keyboard Input


 INT 21h function 3Fh uses file handles to request keyboard input.
o Registers settings:
 AH = Function 3F40h
 BX = File handle 00
 CX = Maximum number of characters to accept
 DX = Address of area for entering characters
 A successful INT operation clear the carry flag and sets the AX with the number of characters entered.

Ex.
Kbinput db 20 dup(‘ ‘)
………….
Mov ah,3fh
Mov bx,00
Mov cx,20
Lea dx,kbinput
Int 21h

Hands on Exercise using Debug.

Mov ah,3fh
Mov bx,00
Mov cx,0C
Mov dx,10f
Int 21h
Jmp 100
Db 20 20 20 20 20 20 20 20 20 20 20 20

You might also like