22
KEYBOARD INTERRUPTs 8086 08/14/2022 1

Keyboard interrupt

  • Upload
    techmx

  • View
    6.328

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Keyboard interrupt

04/10/2023

1

KEYBOARD INTERRUPTs8086

Page 2: Keyboard interrupt

04/10/2023

2

The Purpose of Interrupts

Interrupts are particularly useful when interfacing I/O devices that

provide or require data at relatively low data transfer rates .

If the person using the keyboard typed one character per second. The

software of the Processors waited an entire second between each key

stroke for the person to type another key .

This process was such a tremendous waste of time that designers

developed another process, Interrupt processing to handle this

situation.

Interrupt processing allows the microprocessor to execute other

software while the keyboard operator is thinking about what key to

type next.

Page 3: Keyboard interrupt

04/10/2023

3

DOS and BIOS Interrupts

DOS and BIOS interrupts are used to perform

some very useful functions, such as displaying

data to the monitor, reading data from

keyboard, etc.

They are used by identifying the interrupt

option type, which is the value stored in

register AH and providing, whatever extra

information that the specific option requires.

Page 4: Keyboard interrupt

04/10/2023

4

Introduction

SOFTWARE INTERRUPT:

The 8086 INT instruction can be used to cause the 8086 to do any one of 256

possible interrupt types.

The desired type is specified as part of the instruction.

Software interrupts produced by the INT instructions have many uses.

For example: INT 3 instruction to insert breakpoints in programs for

debugging.

Another use of Software interrupt INT is to test various interrupts-service

procedures.

For example: INT 0 instruction to send execution to a divide-by-zero interrupt

–service procedure without having to run the actual division program.

Page 5: Keyboard interrupt

04/10/2023

5

INT Instruction

The term type in the instruction format refers to a number between 0

and 255 which identifies the interrupt. When an 8086 executes an INT

instruction. It will:

1. Decrement the stack pointer by 2 and push the flags onto the stack.

2. Decrement the stack pointer by 2 and push the contents of CS onto the stack.

3. Decrement the stack pointer by 2 and push the offset of the next instruction

after the INT number instruction on the stack.

4. Get a new value for IP from an absolute memory address of 4 times the type

specified in the instruction. For an INT 8 instruction. For example, the new IP

will be read from address 00020H.

5. Get a new value for CS from an absolute memory address of 4 times the type

specified in the instruction plus 2. For an INT 8 instruction, for example, the

new value of CS will be read from address 00022H.

6. Reset both IF and TF. Other flags are not affected.

Page 6: Keyboard interrupt

04/10/2023

6

INT 21h Instruction

Hence in this section we are going to see about INT

instructions used for Keyboard.(INT 21 h-DOS Interrupt)

The int 21 h instructions are used to interrupt through

the Keyboard, Files, Directives.

Depending on the value that is moved to the ‘ah’ the

operations will be done.

The following slides will explain the different operations

performed.

Page 7: Keyboard interrupt

04/10/2023

7

INT 21h Instruction

INT 21h / AH=1 - read character from standard input, with echo, result is

stored in AL.

if there is no character in the keyboard buffer, the function waits until any key

is pressed.

example:

mov ah, 1

int 21h

INT 21h / AH=2 - write character to standard output.

entry: DL = character to write, after execution AL = DL.

example:

mov ah, 2

mov dl, 'a'

int 21h

Page 8: Keyboard interrupt

04/10/2023

8

INT 21h Instruction INT 21h / AH=5 - output character to printer.

entry: DL = character to print, after execution AL = DL.

example:

mov ah, 5

mov dl, 'a'

int 21h  

INT 21h / AH=7 - character input without echo to AL.

example:

mov ah, 7

int 21h   INT 21h / AH=9 - output of a string at DS:DX. String must be terminated by '$'.

example:msg db "hello world $“.codemov ax,@datamov ds,axmov dx,offset msgmov ah,9int 21hret

Page 9: Keyboard interrupt

04/10/2023

9

INT 21h Instruction

INT 21h / AH=0Ah - input of a string to DS:DX,

Example:

mov ax,@data

mov ds,ax

mov ah,0Ah

int 21h

INT 21h / AH=25h - set interrupt vector;

input: AL = interrupt number. DS:DX -> new interrupt handler.

INT 21h / AH=2Ah - get system date;

return: CX = year (1980-2099). DH = month. DL = day. AL = day of week

(00h=Sunday)

Page 10: Keyboard interrupt

04/10/2023

10

Other INT 21h Instruction

INT 21h / 6h;direct console input or output.

INT 21h/0Bh; Get input Status

INT 21h/0Ch; Flush keyboard buffer and read standard input

INT 21h/0Eh; Select default drive

INT 21h/19h; Get current default drive

INT 21h/25h; Set interrupt vector

INT 21h/35h; Get interrupt Vector

INT 21h/39h; Make directory

INT 21h/3Ah; Remove directory

INT 21h/3Bh; Set current directory

Page 11: Keyboard interrupt

04/10/2023

11

Other INT 21h instruction

INT 21h/3Ch;create or truncate file

INT 21h/3Dh;Open Existing file

INT 21h/3Eh;Close file

INT 21h/3Fh;Read from File

INT 21h/40h;Write to file

INT 21h/41h;Delete File

INT 21h/42h;Set current File Position

INT 21h/47h;Get current Directory

INT 21h/4Ch;return control to the operating system(STOP PROGRAM)

INT 21h/56h; rename file/move file 

Page 12: Keyboard interrupt

04/10/2023

12

Example Programs

INPUT A CHARACTER AND PRINT THE CHARACTER IN THE OUTPUT

.model small

.stack 100h

.codemov ax, @datamov ds, axmov ah, 1h ; keyboard input subprogramint 21h ; read character into almov dl, al ; copy character to dlmov ah, 2h ; character output subprogramint 21h ; display character in dl

end

Page 13: Keyboard interrupt

04/10/2023

13

Example Programs

INPUT THE STRING:.model small.stack 100h.code

mov ax, @datamov ds , axmov ah,0Ahint 21h

end 

PRINT THE STRING IN THE OUTPUT.model small.data

msg db "hello world $".stack 100h.code

mov ax, @datamov ds, axmov dx, offset msgmov ah,9int 21hret

end

Page 14: Keyboard interrupt

04/10/2023

14

Example Programs

GET SYSTEM DATE AND TIME:

// DATE:.model small.stack 100h.code

mov ax, @datamov ds, axmov ah, 2Ah; int 21h ; end

//TIME:.model small.stack 100h.code

mov ax,@datamov ds,axmov ah, 2Ch; int 21h ;

end

Page 15: Keyboard interrupt

04/10/2023

15

INT 16h INSTRUCTION

INT 16h is the basic BIOS keyboard operation used

extensively by software developers and provides the following

services according to a function code that you load in AH.

INT 16h/03h: set typematic Repeat rate

INT 16h/05h: Keyboard write.

INT 16h/10h: Read keyboard Character

INT 16h/11h: Determine whether character is present or not

INT 16h/12h: Return Keyboard Status.

Page 16: Keyboard interrupt

04/10/2023

16

INT 10h Instructions

INT 10h instruction is used for the video mode.

Even this INT instruction has many operations that

works according to the value moved onto the ‘ah’.

Option 0H – Sets video mode.

Registers used:

AH = 0H

AL = Video Mode.

Page 17: Keyboard interrupt

04/10/2023

17

INT 10h Instructions

The following are some of the services offered by INT 10 H.

INT 10H/00H; set video mode

INT 10H/01H; set cursor size

INT 10H/02H; set cursor position

INT 10H/03H; return cursor status

INT 10H/05H; select active page

INT 10H/06H; scroll up screen

INT 10H/07H; scroll down screen

INT 10H/0Ah; display character

INT 10H/0CH; Write pixel dot

INT 10H/13H; Return video information

Page 18: Keyboard interrupt

04/10/2023

18

INT 10h Instructions

INT 10h / AH = 09h - write character and attribute at cursor position.

input:AL = character to display.BH = page number.BL = attribute.CX = number of times to write character. 

INT 10h / AH = 0Ah - write character only at cursor position.

input:AL = character to display.BH = page number.CX = number of times to write character.   

Page 19: Keyboard interrupt

04/10/2023

19

INT 10h Instructions

INT 10h / AH = 0Ch - change color for a single pixel.

input:AL = pixel colorCX = column.DX = row.example: mov al, 13h mov ah, 0 int 10h ; set graphics video mode. mov al, 1100b mov cx, 10 mov dx, 20 mov ah, 0ch int 10h ; set pixel.  

INT 10h / AH = 0Dh - get color of a single pixel.

input:CX = column.DX = row.output:AL = pixel color

Page 20: Keyboard interrupt

04/10/2023

20

INT 10h Instructions

INT 10h / AH = 13h - write string.

input:AL = write mode:    bit 0: update cursor after writing;    bit 1: string contains attributes.BH = page number.BL = attribute if string contains only characters (bit 1 of AL is zero).CX = number of characters in string (attributes are not counted).DL,DH = column, row at which to start writing.ES:BP points to string to be printed.

Page 21: Keyboard interrupt

04/10/2023

21

INT 10h Instructions

example:

mov al, 1

mov bh, 0

mov bl, 0011_1011b

mov cx, msg1end - offset msg1 ; calculate message size.

mov dl, 10

Mov dh, 7

push cs

pop es

mov bp, offset msg1

mov ah, 13h

int 10h

jmp msg1end

msg1 db " hello, world! “

msg1end:  

Page 22: Keyboard interrupt

04/10/2023

22

THANK YOU