17.1 int 9 interrupt routine processing of keyboard input
Int 9 after executing the interrupt routine, it is placed in the keyboard buffer in the CPU. Keyboard buffer in word units 16, 15 may store the scan code and key corresponding to the ASCII code.
A, enter the process B, C, D, E, shift_A, A is:
17.2 use int 16h interrupt routine reads the keyboard buffer
int 16h interrupt routine is one of the most important functions is contained in a read keyboard input from the keyboard buffer, the function number is 0.
Then on a content, int 16h keyboard buffer read process:
- int 16h Interrupt routine functions No. 0:
(1) whether there is data to detect the keyboard buffer;
(2) do not then continue to step 1;
(3) first read the keyboard input buffer word units;
(4 ) into the read scan code ah, ASCII code into Al;
(. 5) has been read keyboard input removed from the buffer.
int 9 int 16h interrupt routine and interrupt routines cooperating programs:
Interrupt routine | Features | When to Run |
---|---|---|
int 9 | Writing to the keyboard buffer | Data is written to the keyboard buffer when a key is pressed |
int 16h | Is read out from the buffer | When the application calls them, the data is read from the keyboard buffer |
17.3 input string
;子程序:字符栈的入栈、出栈和显示
charstack: jmp short charstart
table dw charpush,charpop,charshow
top dw 0
charstart: push bx
push dx
push di
push es
cmp ah,2
ja sret
mov bl,ah
mov bh,0
add bx,bx
jmp word ptr table[bx]
charpush: mov bx,top
mov [si][bx],al
inc top
jmp sret
charpop: cmp top,0
je sret
dec top
mov bx,top
mov al,[si][bx]
jmp sret
charshow: mov bx,0b800h
mov es,bx
mov al,160
mov ah,0
mul dh
mov di,ax
add dl,dl
mov dh,0
add di,dx
mov bx,0
charshows: cmp bx,top
jne noempty
mov byte ptr es:[di],' '
jmp sret
noempty: mov al,[si][bx]
mov es:[di],al
mov byte ptr es:[di+2],' '
inc bx
add di,2
jmp charshows
sret: pop es
pop di
pop dx
pop bx
ret
;接收字符串输入程序
getstr: push ax
getstrs: mov ah,0
int 16h
cmp al,20h
jb nochar ;ASCII码小于20h,说明不是字符
mov ah,0
call charstack ;字符入栈
mov ah,2
call charstack ;显示栈中的字符
jmp getstrs
nochar: cmp ah,0eh ;退格键的扫描码
je backspace
cmp ah,1ch ;Enter键的扫描码
je enter
jmp getstrs
backspace: mov ah,1
call charstack ;字符出栈
mov ah,2
call charstack ;显示栈中的字符
jmp getstrs
enter: mov al,0
mov ah,0
call charstack ;0入栈
mov ah,2
call charstack ;显示栈中的字符
pop ax
ret
The end…