0
我讀了一本關於Assembly的書。它提供了例如鍵盤的I/O驅動程序:組裝 - I/O控制器(鍵盤驅動程序)
section .data
ESC_KEY EQU 1BH ; ASCII code for ESC key
KB_DATA EQU 60H ; 8255 port PA
section .text
global _start
_start:
key_up_loop:
;Loops until a key is pressed i.e., until PA7 = 0.
; PA7 = 1 if a key is up.
in AL, KB_DATA ; read keyboard status & scan code
test AL, 80H ; PA7 = 0?
jnz key_up_loop ; if not, loop back
and AL,7FH ; isolate the scan code
..Translate scan code to ASCII code in AL..
cmp AL,0 ; ASCII code of 0 => uninterested key
je key_down_loop
cmp AL,ESC_KEY ; ESC key---terminate program
je done
display_ch:
; char is now in AL
..Print character AL to screen..
key_down_loop:
in AL,KB_DATA
test AL, 80H ; PA7 = 1?
jz key_down_loop ; if not, loop back
mov AX,0C00H ; clear keyboard buffer
int 21H ; (System interrupt)
jmp key_up_loop
Done:
mov AX,0C00H ; clear keyboard buffer
int 21H
..Exit Program..
我沒有understant指令:test AL, 80H
,什麼是目的,以及它如何檢查,通過這種方式,PA7 = 0?
編輯:我也很樂意解釋有關key_down_loop
部分。爲什麼我們需要這個?我們可以做下一個變化:
cmp AL,0 ; ASCII code of 0 => uninterested key
je key_up_loop
,然後的key_down_loop
所有的部分是無用的。我錯過了什麼?
謝謝。