x86汇编中断code [英] x86 assembler interrupts code

查看:222
本文介绍了x86汇编中断code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    #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 ;
    }

嘿,我正在写一个程序集code ..我试图解决一个问题,中断它要求我做出一个长像按钮一键处理,我真的stucked在这里!所以请有人可以帮助我或者给我一个direcion如何继续......当我preSS按钮ZF == 0,当我离开按钮ZF == 1这可能会帮助
 非常感谢

hey i'm writing an assembly code .. i'm trying to solve an interrupt question which asks me to make a long button treated like one button and i`m stucked here !! so please somebody can help me or give me a direcion how continue... when i press the button ZF==0 and when i leave the button ZF==1 this may help thanks alot

推荐答案

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

In your own keyboard interrupt handler you can have something like this (this is in YASM/NASM syntax, not tested):

编辑:改写了code,添加评论和链接

rewrote the code, added comments and links.

@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.

主要code(不属于中断控制器):

The main code (does not belong to interrupt controller):

@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

一些有用的链接:

Some useful links:

OSDev:中断:关于中断一个有用的文章

OSDev: Interrupts: a useful article about interrupts.

OSDev:8042PS / 2控制器:有用的有关键盘的信息处理

OSDev: "8042" PS/2 Controller: useful information about keyboard handling.

OSDev:8259 PIC :约8259可编程中断控制器信息

OSDev: 8259 PIC: information about 8259 Programmable Interrupt Controller.

这篇关于x86汇编中断code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆