Hi, I am trying to get some assembly code to run in C. I am using mingw32 gcc compiler in a code blocks environment if that matters, and i want to get this code to store the keyboard's input to var kin.
assembly --- in al, 64h
From what I understand that line is suppodsed to read keyboard input and store it in the AL register.
When I use this C code it compiles fine no errors or warning but when i execute it, it gives me a segfault and i cannot figure out how to fix this. I've tried looking at various sites for inline assembly but none of them cover using ports for i/o if some one has any websites i could view or code that would be very much appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void){
while(1){
char kin;
asm(
"movw $0x64, %%dx;"
"inb %%dx, %%al;"
"movb %%al, %0;"
:"=r"(kin)
:
:"%al", "%dx");
printf("%c\n", kin);
}
}
( note i've also tried using the i/o address of 60h and still same result. Also i have tried making everything relavent to a byte, word or dword with regards to the registers the kin variable and the suffix letter after the asm instruction)
I am not a big fan of assembly but i figure getting to know a little would be helpful and learning to use it in a C environment will keep me from having to dive into full Assembly language usage and using MASM NASM etc.