Basic Input Output System BIOS BIOS refers to
Basic Input Output System BIOS • BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer. • A BIOS function is invoked using the INT instruction. The actual function is specified by the contents of AH. • ROM BIOS refers to BIOS procedures that are stored in a ROM placed on the motherboard. Some typical ROM BIOS are: – – INT 10 H INT 13 H INT 14 H INT 16 H Video Driver Disk Driver Serial Port Driver Keyboard Driver • DOS BIOS refers to BIOS that are loaded from a disk after the computer is booted up. Most DOS BIOS are invoked using the INT 21 H instruction. BIOS 1
Character Input from keyboard with Echo • INT 21 H Function 01 H: – – Call With: AH = 01 H Returns: AL = ASCII character pressed. Note: If AL is zero, then a function key is pressed. Example: The following macro reads a one digit number from the keyboard and returns the corresponding binary value in AL. GET 1 MACRO MOV AH, 01 INT 21 H AND AL, 0 FH GET 1 ENDM BIOS ; Specify function 01 ; Call DOS BIOS ; Convert from ASCII to binary 2
Display Character on Standard Output Device • INT 21 H Function 02 H: – – Call With: AH = 02 H DL = ASCII code of character to be displayed Returns: AL = ASCII code of character displayed Note: Standard output device is normally the monitor. Example: The following macro displays a one digit number on the screen. The number is passed in DL as a binary number. DSP 1 MACRO OR DL, 30 H MOV AH, 02 INT 21 H DSP 1 ENDM BIOS ; Convert from binary to ASCII ; Specify function 02 ; Call DOS BIOS 3
Display a Character String • INT 21 H Function 09 H: – – Call With: AH = 09 H DS: DX = Segment: Offset address of the string. Returns: All registers unchanged. Note: Displays a character string up to the first occurrence of the dollar sign "$". Example: The following macro displays the character string MSG on the screen. DMSG MACRO MSG MOV DX, Offset MSG; Point to MSG MOV AH, 09 ; Specify function 09 INT 21 H ; Call DOS BIOS DMSG ENDM BIOS 4
Buffered Keyboard Input • INT 21 H Function 0 AH: – – – BIOS Call With: AH = 0 AH DS: DX = Segment: Offset address of the buffer The first byte in the buffer should be loaded with the size of the buffer, i. e. the maximum number of characters to be input. Returns: All registers unchanged. The second byte in the buffer is equal to the number of characters entered. The characters entered are stored in the buffer starting from the third byte. Note: The functions ends if the user has typed in a number of characters equal to the first value in the buffer, or if the user has pressed the “Enter” key. 5
Buffered Keyboard Input: - Example The following procedure prompts the user to type in a text up to 30 characters long. The text entered is stored in the buffer BUF 1. The procedure uses the DSPM macro of the previous example. ORG 100 H MSG 1 0 DH, ’$’ BUF 1 MAIN DSPM MOV INT RET MAIN BIOS DB ‘Type in a text up to 30 characters long’, 0 AH, DB 30, 00, 30 DUP(? ) PROC NEAR MSG 1 ; Display MSG 1 DX, Offset BUF 1 ; Point to BUF 1 AH, 0 AH ; Specify function 0 A 21 H ; Call DOS BIOS ENDP 6
ASCII Codes • ASCII code is a standard 8 -bit binary code for alphanumeric characters. • It defines: – a group of control characters (00 H to 20 H and 7 FH for Delete) – a group of printable characters (21 H to 7 EH) – a group of special graphics or multilingual characters (80 H to FFH) ASCII Control Characters 00 01 02 03 04 05 06 07 BIOS NUL SOH STX EOT ENQ ACK BEL 08 09 0 A 0 B 0 C 0 D 0 E 0 F BS HT LF VT FF CR SO SI 10 11 12 13 14 15 16 17 DLE DC 1 DC 2 DC 3 DC 4 NAK SYN ETB 18 19 1 A 1 B 1 C 1 D 1 E 1 F CAN EM SUB ESC FS GS RS US 7
ASCII Codes - Printable Characters 20 Space 21 ! 22 ” 23 # 24 $ 25 % 26 & 27 ’ 28 ( 29 ) 2 A * 2 B + 2 C , 2 D 2 E. 2 F / BIOS 30 31 32 33 34 35 36 37 38 39 3 A 3 B 3 C 3 D 3 E 3 F 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 40 41 42 43 44 45 46 47 48 49 4 A 4 B 4 C 4 D 4 E 4 F @ A B C D E F G H I J K L M N O 50 51 52 53 54 55 56 57 58 59 5 A 5 B 5 C 5 D 5 E 5 F P Q R S T U V W X Y Z [ ] ^ _ 60 61 62 63 64 65 66 67 68 69 6 A 6 B 6 C 6 D 6 E 6 F ` a b c d e f g h i j k l m n o 70 71 72 73 74 75 76 77 78 79 7 A 7 B 7 C 7 D 7 E 7 F p q r s t u v w x y z { | } ~ Del 8
EXAMPLE(1/2) • x 86 Assembly program that asks for two numbers and prints their sum TITLE printsum. data ; data segment ORG 100 H ; only if com program MSG 1 DB ‘Please enter a number’, 10, 13, ‘$’ MSG 2 DB ‘sum = ’, 10, 13, ‘$’. code ; code segment Start: mov ax, @data mov ds, ax LEA DX, MSG 1 ; OR MOV DX, OFFSET MSG 1 MOV AH, 09 H ; Printing MSG 1 INT 21 H MOV AH, 01 H INT 21 H ; reading number 1 from keyboard MOV BL, AL ; moving number 1 to BL SUB BL, 30 h ; Subtracting ascii offset LEA DX, MSG 1 MOV AH, 09 H ; Printing MSG 1 INT 21 H MOV AH, 01 H INT 21 H ; reading number 2 from keyboard SUB AL, 30 h ; Subtracting ascii BIOS 9
EXAMPLE(2/2) ADD AL, BL MOV AH, 0 MOV BL, 10 DIV BL MOV BH, AH LEA DX, MSG 2 MOV AH, 09 INT 21 H MOV DL, AL ADD DL, 30 H MOV AH, 02 INT 21 H MOV DL, BH ADD DL, 30 H MOV AH, 02 INT 21 H MOV AH, 4 CH INT 21 H end start BIOS ; Adding the two numbers ; clearing AH for division ; dividing with 10 to obtain decimal digits ; moving remainder to use AH for interrupts ; printing MSG 2 ; could corrupt registers, need to PUSH-POP! ; printing digit 1 ; could corrupt registers, need to PUSH-POP! ; printing digit 2 ; exit to operating system 10
- Slides: 10