C++ asm insertion falls with int command

0

I'm doing homework and trying to read keys from keyboard. I tried to use 16h interrupt and started with this code

int main(){
    char key, shiftKey(2);
    asm ("movb %1, %%al;"
         "int $0x16;"
         "movb %%al, %0;"
    :"=r"(key)
    :"r"(shiftKey)
    :"%al"
    );
    std::cout << int(key);
}

Assembly algorithm is:

  1. pass function number (02) to al register movb 2, al
  2. call interruption int 16h
  3. al now should have mask of all keys like shift, capslock etc.

This code crashes with Process finished with exit code -1073741819 (0xC0000005). So I have no proper info what have I done wrong.

c++
assembly
g++
inline-assembly
asked on Stack Overflow Sep 5, 2018 by sashaaero • edited Sep 5, 2018 by Remy Lebeau

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0