11
BIOS and DOS Programming in DOS INT 10 and 21H

BIOS and DOS Programming in DOS INT 10 and 21H

  • Upload
    mea

  • View
    38

  • Download
    0

Embed Size (px)

DESCRIPTION

BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts. There are some extremely useful subroutines within BIOS or DOS that are available to the user through the INT (Interrupt) instruction. The INT instruction is like a FAR call; when it is invoked - PowerPoint PPT Presentation

Citation preview

Page 1: BIOS and DOS Programming in DOS INT 10 and 21H

BIOS and DOS Programming in DOSINT 10 and 21H

Page 2: BIOS and DOS Programming in DOS INT 10 and 21H

Interrupts

• There are some extremely useful subroutines within BIOS or DOS that are available to the user through the INT (Interrupt) instruction.

• The INT instruction is like a FAR call; when it is invoked– It saves CS:IP and flags on the stack and goes to the subroutine

associated with that interrupt.

– Format:• INT xx ; the interrupt number xx can be 00-FFH

– This gives a total of 256 interrupts

– Two of them are widely used: INT 10H and INT 21H

– Before the services of INT 10H and 21H is requested, certain registers must have specific values in them, depending on the function being requested.

Page 3: BIOS and DOS Programming in DOS INT 10 and 21H

INT 10H

• INT 10H aubroutines are burned into the ROM BIOS of the 80x86-based PC and are used to communicate with the computer’s screen video.

• INT 10H Function 06– AL = number of lines to scroll (with AL=00, window will be cleared)

– BH = attribute of blank rows

– CH, CL = upper row, left column

– DH, DL = lower row, right column

00,00 00,79

24,00 24,79

12,39

Cursor Locations

Page 4: BIOS and DOS Programming in DOS INT 10 and 21H

INT 10H

• INT 10H function 02; setting the cursor to a specific location– Function AH = 02 will change the position of the cursor to any location.– The desired cursor location is in DH = row, DL = column

• EX. Write a program that clears the screen and sets the cursor at the center of the screen

• INT 10H function 03; get current cursor position

– Registers DH and DL will have the current row and column positions and CX provides info about the shape of the cursor.

; clearing the screenMOV AX, 0600H ;scroll the entire pageMOV BH, 07 ; normal attribute (white on black)MOV CX, 0000 ; upper left

MOV DX,184FH ; lower right INT 10H;setting the cursor at the center

MOV AH,02 ; set cursor optionMOV BH, 00 ; page 0MOV DL, 39 ; MOV DH, 12 ;INT 10H

MOV AH, 03MOV BH, 00INT 10H

Page 5: BIOS and DOS Programming in DOS INT 10 and 21H

INT 21H

• INT 21H is provided by DOS to be invoked to perform extremely useful functions.

• INT 21H Option 09: Outputting a string of data to the monitor– INT 21H can be used to send a set of ASCII data to the monitor.

– AH = 09; DX = offset address of the ASCII data to be displayed.

– INT 21H option 09 will display the ASCII data string pointed to by DX until it encounters the dollar sign “$”.

• INT 21H Option 02: Outputting a single character to the monitor– DL is loaded with the character first

DATA_ASC DB ‘The earth is one country’,’$’

MOV AH,09MOV DX, OFFSET DATA_ASC

INT 21H

MOV AH 02MOVE DL,’J’INT 21H

Page 6: BIOS and DOS Programming in DOS INT 10 and 21H

INT 21H

• INT 21H Option 01: Inputting a single character with echo– This function 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.

• INT 21H Option 0AH: Inputting a string of data from the keyboard with echo– AH = 0AH

– DX = offset address at which the address is stored

– First byte specifies the size of the buffer, second byte is the number of characters

ORG 0010HDATA1 DB 6,?,6 DUP(FF)

MOV AH, 00HMOV DX, OFFSET DATA1INT 21H

Ex. What happens if one enters USA and then <RETURN>

0010 0011 0012 0013 0014 0015 0016 0017

06 03 55 53 41 0D FF FF

Page 7: BIOS and DOS Programming in DOS INT 10 and 21H

Example 1

• Clear the screen • Set the cursor to the center• Display the message “This is a test of the display routine”

TITLE PROG SIMPLE DISPLAY PROGRAMPAGE 60,132 .MODEL SMALL .STACK 64;-------------- .DATAMESSAGE DB 'This is a test of the display routine','$';-------------- .CODEMAIN PROC FAR MOV AX,@DATA MOV DS,AX CALL CLEAR ;CLEAR THE SCREEN CALL CURSOR ;SET CURSOR POSITION CALL DISPLAY ;DISPLAY MESSAGE MOV AH,4CH INT 21H ;GO BACK TO DOSMAIN ENDP;---------------

Page 8: BIOS and DOS Programming in DOS INT 10 and 21H

Example 1 Contd.

;THIS SUBROUTINE CLEARS THE SCREENCLEAR PROC MOV AX,0600H ;SCROLL SCREEN FUNCTION MOV BH,07 ;NORMAL ATTRIBUTE MOV CX,0000 ;SCROLL FROM ROW=00,COL=00 MOV DX,184FH ;TO ROW=18H,COL=4FH INT 10H ;INVOKE INTERRUPT TO CLEAR SCREEN RETCLEAR ENDP;THIS SUBROUTINE SETS THE CURSOR AT THE CENTER OF THE SCREENCURSOR PROC MOV AH,02 ;SET CURSOR FUNCTION MOV BH,00 ;PAGE 00 MOV DH,12 ;CENTER ROW MOV DL,39 ;CENTER COLUMN INT 10H ;INVOKE INTERRUPT TO SET CURSOR POSITION RETCURSOR ENDP;THIS SUBROUTINE DISPLAYS A STRING ON THE SCREENDISPLAY PROC MOV AH,09 ;DISPLAY FUNCTION MOV DX,OFFSET MESSAGE ;DX POINTS TO OUTPUT BUFFER INT 21H ;INVOKE INTERRUPT TO DISPLAY STRING RETDISPLAY ENDP END MAIN

Page 9: BIOS and DOS Programming in DOS INT 10 and 21H

Example 2

;Program performs the following, (1) clears the screen, (2) sets the cursor at the beginning ;of the third line from the top of the screen, (3) accepts the message "IBM perSonal ;COmputer" from the keyboard, (4) converts lowercase letters of the message to uppercase, ; (5) displays the converted ;results on the next line.TITLE PROGPAGE 60,132 .MODEL SMALL .STACK 64 .DATABUFFER DB 22,?,22 DUP (?) ;BUFFER FOR KEYED-IN DATA ORG 18HDATAREA DB CR,LF,22 DUP (?),'$' ;AREA TO PLACE DATA AFTER CONVERSIONCR EQU 0DHLF EQU 0AH.CODEMAIN PROC FAR MOV AX,@DATA MOV DS,AX CALL CLEAR ;CLEAR THE SCREEN CALL CURSOR ;SET CURSOR POSITION CALL GETDATA ;INPUT A STRING INTO BUFFER CALL CONVERT ;CONVERT STRING TO UPPER CASE CALL DISPLAY ;DISPLAY STRING DATAREA MOV AH,4CH INT 21H ;GO BACK TO DOSMAIN ENDP

Page 10: BIOS and DOS Programming in DOS INT 10 and 21H

Example 2 Contd.

;THIS SUBROUTINE CLEARS THE SCREENCLEAR PROC MOV BH,07 ;NORMAL ATTRIBUTE MOV CX,0000 ;SCROLL FROM ROW=00,COL=00 MOV DX,184FH ;TO ROW=18H,4FH INT 10H ;INVOKE INTERRUPT TO CLEAR SCREEN RETCLEAR ENDP;THIS SUBROUTINE SETS THE CURSOR TO THE BEGINNING OF THE 3RD LINECURSOR PROC MOV AH,02 ;SET CURSOR FUNCTION MOV BH,00 ;PAGE 0 MOV DL,01 ;COLUMN 1 MOV DH,03 ;ROW 3 INT 10H ;INVOKE INTERRUPT TO SET CURSOR RETCURSOR ENDP;---------------;THIS SUBROUTINE DISPLAYS A STRING ON THE SCREENDISPLAY PROC MOV AH,09 ;DISPLAY STRING FUNCTION MOV DX,OFFSET DATAREA ;DX POINTS TO BUFFER INT 21H ;INVOKE INTERRUPT TO DISPLAY STRING RETDISPLAY ENDP;---------------

Page 11: BIOS and DOS Programming in DOS INT 10 and 21H

Example 2 Contd.

;THIS SUBROUTINE PUTS DATA FROM THE KEYBOARD INTO A BUFFERGETDATA PROC MOV AH,0AH ;INPUT STRING FUNCTION MOV DX,OFFSET BUFFER ;DX POINTS TO BUFFER INT 21H ;INVOKE INTERRUPT TO INPUT STRING RETGETDATA ENDP;THIS SUBROUTINE CONVERTS ANY SMALL LETTER TO ITS CAPITALCONVERT PROC MOV BX,OFFSET BUFFER MOV CL,[BX]+1 ;GET THE CHAR COUNT SUB CH,CH ;CX = TOTAL CHARACTER COUNT MOV DI,CX ;INDEXING INTO BUFFER MOV BYTE PTR[BX+DI]+2,20H ;REPLACE CR WITH SPACE MOV SI,OFFSET DATAREA+2 ;STRING ADDRESSAGAIN: MOV AL,[BX]+2 ;GET THE KEYED-IN DATA CMP AL,61H ;CHECK FOR 'a' JB NEXT ;IF BELOW, GO TO NEXT CMP AL,7AH ;CHECK FOR 'z' JA NEXT ;IF ABOVE GO TO NEXT AND AL,11011111B ;CONVERT TO CAPITALNEXT: MOV [SI],AL ;PLACE IN DATA AREA INC BX LOOP AGAIN ;LOOP IF COUNTER NOT ZERO RETCONVERT ENDP END MAIN