Assembly x86汇编程序中断代码 #包括 #包括 无效中断(*int9save)(无效) 无效中断消除多次按下(无效) { int9save=getvect(9); setvect(9,消除多次按压); asm{ 莫夫啊,0 int 16h MOV扫描温度,啊 CMP-ZF,0 } } 无效中断取消删除\u多个\u按() { setvect(9,int9save); } 真空总管(真空) { char-str[100]; 整数检查=1; 字符扫描温度; 无符号整数扫描码; 消除多次按压(); printf(“输入单词”); scanf(“%s”,str); 扫描代码=(无符号整数)扫描温度; printf(“单词是:\n”); printf(“%s”,str); 取消消除多重压力(); 返回; }

Assembly x86汇编程序中断代码 #包括 #包括 无效中断(*int9save)(无效) 无效中断消除多次按下(无效) { int9save=getvect(9); setvect(9,消除多次按压); asm{ 莫夫啊,0 int 16h MOV扫描温度,啊 CMP-ZF,0 } } 无效中断取消删除\u多个\u按() { setvect(9,int9save); } 真空总管(真空) { char-str[100]; 整数检查=1; 字符扫描温度; 无符号整数扫描码; 消除多次按压(); printf(“输入单词”); scanf(“%s”,str); 扫描代码=(无符号整数)扫描温度; printf(“单词是:\n”); printf(“%s”,str); 取消消除多重压力(); 返回; },assembly,x86,interrupt,keyboardinterrupt,Assembly,X86,Interrupt,Keyboardinterrupt,嘿,我在写汇编代码。。我正在试图解决一个中断问题,这个问题要求我把一个长按钮当作一个按钮来对待,我在这里被卡住了!!所以请有人能帮我或给我一个指示如何继续。。。当我按下按钮ZF==0和离开按钮ZF==1时,这可能会有所帮助 非常感谢在您自己的键盘中断处理程序中,您可以有这样的东西(这是YASM/NASM语法,未经测试): 编辑:重写代码,添加注释和链接 #include <studio.h> #include <dos.h> void interr

嘿,我在写汇编代码。。我正在试图解决一个中断问题,这个问题要求我把一个长按钮当作一个按钮来对待,我在这里被卡住了!!所以请有人能帮我或给我一个指示如何继续。。。当我按下按钮ZF==0和离开按钮ZF==1时,这可能会有所帮助
非常感谢

在您自己的键盘中断处理程序中,您可以有这样的东西(这是YASM/NASM语法,未经测试):

编辑:重写代码,添加注释和链接

    #include <studio.h>
    #include <dos.h>
    void interrupt (*int9save) (void)
    void interrupt eliminate_multiple_press(void)
    {
    int9save=getvect(9);
    setvect(9,eliminate_multiple_press);
    asm {
    MOV AH,0
    int 16h
    MOV scan_temp,AH
    CMP ZF,0
    }
    }
    void interrupt uneliminate_multiple_press()
    {
    setvect(9,int9save);
    }
    void main(void)
    {
    char str[100];
    int check=1;
    char scan_temp;
    unsigned int scan_code ;
    eliminate_multiple_press();
    printf("enter a word\n");
    scanf("%s",str);
    scan_code=(unsigned int) scan_temp;
    printf("the word is:\n");
    printf("%s",str);
    uneliminate_multiple_press();
    return ;
    }
主代码(不属于中断控制器):

一些有用的链接:

:一篇关于中断的有用文章

:有关键盘处理的有用信息


:关于8259可编程中断控制器的信息。

以何种方式卡住-它是否编译?如果它编译了,会发生什么?这是什么编译器?什么平台-DOS?正如您所写,您的中断处理程序本身正在为键盘中断设置中断服务例程。这绝对不是你想在这里做的。将
getvect
/
setvect
对移动到
main
中,然后可以进入下一个问题:无法从ISR内部使用BIOS的键盘接口(int 16h)。查看@nrz的答案,了解您在ISR中需要做什么。投票关闭作为调试帮助,请最小化。然后退出??20小时是什么?好的,我不知道我知道:MOV啊,0 INT 16h,但你能解释20小时、60小时和7fh吗?@DeebAndrawis我改进了我的答案,请参阅提供的链接和代码注释(我试图用逗号更详细地解释代码)。好的,不幸的是,我没有TASM,因为我想让它成为一个有效的例子,至少在某些语法上是这样,所以我选择了我知道的YASM/NASM。您可能需要替换的内容:
->
dup
次128 db 0
->
db 128 dup 0
;十六进制数:
0x[0-9a-f][0-9a-f]
->
[0-9a-f][0-9a-f]
<代码>字节->
字节ptr
@my_int9:
    cli
    push ax     ; push ax (you can create a stack frame too, if you wish).
    push bx     ; push bx.

    in al,0x60  ; read scancode from keyboard port 60h to al.

    cmp al,[cs:last_scancode] ; compare the current and last scancodes.
    je @ready                 ; jump if its the same scancode, nothing to do.

    test al,0x80              ; test highest bit of al to see if it's release
                              ; or not.
                              ; test does logical AND without saving the result,
                              ; it only updates the flags
                              ; (and al,0x80 would be OK too).

    jnz @key_released         ; jump if it's a released key.

    ; OK, we have a new key.

@new_key:
    movzx bx,al               ; copy the scancode from al to bx.

    mov [cs:last_scancode],al ; store the current scancode into memory.

    ; Do something with the new key here.

    ; This is an example.

    mov al,1
    mov [cs:bx+keys_pressed],al ; set the corresponding byte of array to 1
                                ; (pressed).
    mov [cs:something_to_do],al ; set the flag "something to do" to 1.
                                ; (so that the main code needs to scan through
                                ; keys_pressed array only when there's at least
                                ; 1 key that hasn't been handled yet).

@key_released:
    ; Do something here upon the key release if you wish...
    ; This really depends on what do you want to if with released keys.

    ; If you want that keypresses are handled even after the corresponding key
    ; is  are released and that the the key release shouldn't cause any action,
    ; (in the case you don't poll that repeatedly), don't do anything here.
    ;
    ; If you want that keypresses are _not_ handled after the release, then set
    ; the corresponding byte of keys_pressed array to 0
    ; (uncomment the 3 lines below):
    ;
    ; and al,0x7F                     ; clear the highest bit.
    ; movzx bx,al                     ; copy the scancode from al to bx.
    ; mov [cs:bx+keys_pressed],byte 0 ; mark the key as not pressed.

@ready:
    mov al,0x20             ; write byte 20h to port 20h to inform PIC.
    out 0x20,al             ; (programmable interrupt controller) that it's OK
                            ; to continue sending interrupts.
    pop bx
    pop ax
    sti
    iret

last_scancode db 0

keys_to_handle db 0           ; in the main code you can poll for this.
                              ; After handling the keys, set this to 0.

keys_pressed times 128 db 0   ; db 128 dup 0 in some other assemblers
                              ; In the main program code scan through this if
                              ; keys_to_handle is not zero, and set the
                              ; corresponding byte to 0 to not handle it twice.
@main_code_loop:
    test [cs:keys_to_handle], byte 0xFF ; check if there are keys to handle.
    jz @no_keys_to_handle               ; no, nothing to do.

    ; here scan through entire keys_pressed array and set handled keys'
    ; corresponding bytes to 0.
    ; remember to loop through the entire array, there can be several keys to handle.

    mov [cs:keys_to_handle], byte 0     ; set keys_to_handle byte to 0.

@no_keys_to_handle:
    ; do something else