I am trying to programm a bootloader and therefore i use inline assembly. but i have struggles using diffrent methods for diffrent assembly code. I wrote the following as function:
char readInput(){
char i = 'a';
asm(
"mov $0, %%ah;" //parameter for read char
"int $0x16;" //interrupt for read
"mov %%al, %0;" //put readen char in variable i
:"=r" (i) //random register which is free for i
:: "ax" //was used
);
return i;
}
when i call it like 3 times in my main-function f.e.:
readInput();
readInput();
readInput();
and I execute it and press 1x 'd' he reads instant 3x 'd' :( i have no idea why. Does anyone know?
PROBLEM IS SOLVED! Correct code to read input:
char readInput(){
char i = 'a';
asm(
"mov $0, %%ah;" //parameter for read char
"int $0x16;" //interrupt for read
"mov %%al, %0;" //put readen char in variable i
:"=r" (i) //random register which is free for i
:: "ax" //was used
);
asm("");
return i;
}