2012-03-09 38 views
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所有的部分是無用的。我錯過了什麼?

謝謝。

回答

0

test指令對操作數執行邏輯and並根據結果設置標誌。操作數沒有改變。 A test指令是and什麼cmp指令它sub

一些奇怪的原因,「讓我谷歌爲你」是不是在堆棧溢出允許了(也許到違規?),所以直接鏈接:http://www.google.de/search?q=test+x86+instruction

PA7顯然是第7位的地方。我把它留給你瞭解如何轉化爲80H