Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit:08 Software Interrupts

Similar presentations


Presentation on theme: "Unit:08 Software Interrupts"— Presentation transcript:

1 Unit:08 Software Interrupts
Kip Irvine: Assembly Language for Intel-Based Computers

2 Kip Irvine: Assembly Language for Intel-Based Computers
Overview INT Instruction Redirecting Input/Output MS-DOS (INT 21h) Function Calls Output Functions Input Functions Date /Time Functions BIOS Keyboard Input (INT 16h) BIOS Video Control (INT 10h) Recursion Kip Irvine: Assembly Language for Intel-Based Computers

3 Kip Irvine: Assembly Language for Intel-Based Computers
Interrupts Hardware interrupts occur as a response to a hardware device routed through the Intel 8259 Interrupt Controller Software interrupts calls to operating system functions, located in BIOS and resident portion of DOS activated by the INT instruction Kip Irvine: Assembly Language for Intel-Based Computers

4 Kip Irvine: Assembly Language for Intel-Based Computers
INT Instruction The INT instruction is always followed by a hexadecimal number that identifies its type Common examples: INT 10h - video BIOS INT 14h - Serial I/O INT 16h - keyboard BIOS INT 17h - printer services INT 1Ah - Time of day INT 1Ch - User timer INT 21h - DOS services Kip Irvine: Assembly Language for Intel-Based Computers

5 Interrupt Vectoring Process
CPU processes an interrupt instruction using the interrupt vector table, a table of addresses in the lowest 1,024 bytes of memory. Each entry in the table is a 32-bit segment offset address that points to an OS subroutine. The actual address in this table vary from one machine to another. Fig. shows the steps taken by CPU when INT instruction is invoked by a program. Kip Irvine: Assembly Language for Intel-Based Computers

6 Interrupt Vectoring Process
Kip Irvine: Assembly Language for Intel-Based Computers

7 Redirecting Input-Output
Standard Input device and standard output device are collectively called the console, which involves the keyboard for input and the video display for output. From DOS command line, we can redirect standard input so it is read from a file or hardware port rather than a keyboard. Standard output can be redirected so it writes to a file or hardware port rather than the video display. Kip Irvine: Assembly Language for Intel-Based Computers

8 Kip Irvine: Assembly Language for Intel-Based Computers
Example An executable program named prog1.exe can have its I/O redirected with the following command lines: Prog1 > prn output to printer Prog1 < infile.txt Input from file called infile.txt Prog1 < infile.txt > prn input from file, output to printer Kip Irvine: Assembly Language for Intel-Based Computers

9 Standard DOS device names
Description CON Console (video display or keyboard) LPT1 or PRN First parallel printer LPT2, LPT3 Parallel port 2 & 3 COM1, COM2 Serial port 1 & 2 NUL Nonexistent or dummy device Kip Irvine: Assembly Language for Intel-Based Computers

10 DOS Function Calls (INT 21h)
The INT 21h instruction activates a DOS function call The function number (0-255) is placed in the AH register before invoking INT 21h Some functions require that you assign values to certain registers before invoking INT 21h Some functions return values in registers Kip Irvine: Assembly Language for Intel-Based Computers

11 Kip Irvine: Assembly Language for Intel-Based Computers
Simple Console I/O mov ah, ; single character input int 21h mov ah, ; select Dos function 2 mov dl,'A‘ ; character to be displayed int 21h ; call dos to do the job mov ah, ; string output mov dx,offset message Kip Irvine: Assembly Language for Intel-Based Computers

12 Kip Irvine: Assembly Language for Intel-Based Computers
INT 21h: Standard Input • 01h Filtered Input With Echo • 06h Direct Input Without Waiting • 07h Direct Input, No Ctrl-Break • 08h Direct Input with Ctrl-Break • 0Ah Buffered Input • 0Bh Get Input Status • 0Ch Clear Input Buffer, Invoke Input Function • 3Fh Read From File or Device Kip Irvine: Assembly Language for Intel-Based Computers

13 Comparison of Standard Input
Kip Irvine: Assembly Language for Intel-Based Computers

14 Keyboard Parameter Record (Function 0Ah)
Kip Irvine: Assembly Language for Intel-Based Computers

15 3Fh: Read from File or Device
When the user presses Enter at the end of the input, two bytes (0Dh,0Ah) are appended to the string in the input buffer and the count in AX includes the extra characters. buffer db 127 dup(0) . mov ah,3Fh ; read from file/device mov bx, ; device = keyboard mov cx, ; request 127 bytes maximum mov dx,offset buffer int 21h ; AX = number chars typed + 2 Kip Irvine: Assembly Language for Intel-Based Computers

16 40h: Write to File or Device
buffer db 127 dup(0) count dw ? . mov ah,40h ; read from file/device mov bx, ; device = console mov cx,count ; number of chars to write mov dx,offset buffer int 21h Kip Irvine: Assembly Language for Intel-Based Computers

17 Date/Time Functions (Get Date 2Ah)
Function 2Ah returns the current system date, placing the year number in CX the month number in DH and the day of the week in AL. The day number in AL uses the value of 0 for Sunday, 1 for Monday and so on The following statements call the function and saves the value: mov ah,2Ah int 21h mov year,cx mov month,dh mov day,dl mov dayOfWeek,al Kip Irvine: Assembly Language for Intel-Based Computers

18 Date/Time Functions (Set Date 2Bh)
Function 2Bh sets the current date, using the same registers as function 2Ah (get date) The function returns the value 0 in AL if the change was successful. Example mov ah,2Bh mov cx,year mov dh,month mov dl,day int 21h cmp al,0 jne badDate Kip Irvine: Assembly Language for Intel-Based Computers

19 Date/Time Functions (Get Time 2Ch)
Function 2Ch returns the current system time, placing the hour in CH the minutes in CL and the seconds in DH and the hundredth of seconds in DL. The following statements call the function and saves the value: mov ah,2Ch int 21h mov hours,ch mov minutes,cl mov seconds,dh Kip Irvine: Assembly Language for Intel-Based Computers

20 Date/Time Functions (Set Time 2Dh)
Function 2Dh sets the current time, using the same registers as function 2Ch (get time) The function returns the value 0 in AL if the change was successful. Example mov ah,2Dh mov ch,hours mov cl,minutes mov dh,seconds int 21h cmp al,0 jne badTime Kip Irvine: Assembly Language for Intel-Based Computers

21 INT 16h BIOS Keyboard Input
A direct way to retrieve keyboard input is through the INT 16h keyboard services. The function code is placed in AH before calling INT 16h. The following example shows how to wait for a keystroke with INT 16h. Suppose F1 key were pressed . Mov ah,10h ;requests BIOS keyboard input Int 16h ;AH =3Bh, AL= 0 Kip Irvine: Assembly Language for Intel-Based Computers

22 INT 16h BIOS Keyboard Input
Kip Irvine: Assembly Language for Intel-Based Computers

23 Kip Irvine: Assembly Language for Intel-Based Computers
Keyboard Status Byte Kip Irvine: Assembly Language for Intel-Based Computers

24 Keyboard Input Using INT 16h
Use INT 16h to input any key, including function keys, arrow keys, and other extended keys. mov ah,10h ; wait for key int 16h ; AH=scan code, AL=ASCII code Kip Irvine: Assembly Language for Intel-Based Computers

25 Kip Irvine: Assembly Language for Intel-Based Computers
Keyboard Scan Codes A keyboard scan code is a unique 8-bit binary number associated with a particular keyboard key. A list of frequently used codes is inside the front cover of the book. Here are samples: Home 47h End 4Fh PgUp 49h PgDn 51h F1 function key 3Bh F2 function key 3Ch F3 function key 3Dh F4 function key 3Eh Kip Irvine: Assembly Language for Intel-Based Computers

26 Common ASCII Control Characters
Kip Irvine: Assembly Language for Intel-Based Computers

27 Video Attribute Layout
(MSDOS mode only) If your program is running in an MS-DOS window under Windows/NT, your background color is stored in bits 4-7 of the attribute bit, and blinking is disabled. Kip Irvine: Assembly Language for Intel-Based Computers

28 3-bit Background Colors
The following background colors are used only when running in full-screen mode or in pure MSDOS mode (by rebooting). Kip Irvine: Assembly Language for Intel-Based Computers

29 4-bit Foreground Colors
Kip Irvine: Assembly Language for Intel-Based Computers

30 4-bit Background Colors
Kip Irvine: Assembly Language for Intel-Based Computers

31 Table 9. Listing of INT 10h Functions (1 of 2)
Kip Irvine: Assembly Language for Intel-Based Computers

32 Table 9. Listing of INT 10h Functions (2 of 2)
Kip Irvine: Assembly Language for Intel-Based Computers

33 INT 10h (09h) Write Character and Attribute
This function does not advance the cursor, so you have to do that separately mov ah, ; write character and attribute mov al,0Ah ; ASCII character 0Ah mov bh, ; video page 0 mov bl,2 ; color (attribute) = green mov cx, ; display it one time int 10h Kip Irvine: Assembly Language for Intel-Based Computers

34 Example: Write a Color String
string db "ABCDEFGHIJKLMOP" count = ($-string) color db 1 . mov cx,count mov si,offset string L1: push cx ; save loop counter mov ah, ; write character and attribute mov al,[si] ; character to display mov bh, ; video page 0 mov bl,color ; get the color mov cx, ; display it one time int 10h call AdvanceCursor inc color ; next color inc si ; next character position pop cx ; restore loop counter Loop L1 Kip Irvine: Assembly Language for Intel-Based Computers


Download ppt "Unit:08 Software Interrupts"

Similar presentations


Ads by Google