Page 1 of 1

Strange problem with loop

Posted: Sat Apr 29, 2006 9:36 pm
by srg_13
I am rewriting my keyboard driver (again) and I have ran into this problem: I have a loop in my getchar() function that waits until a key is pressed:

Code: Select all

   while(keypressed!=1)
   {
        __asm__ __volatile__("hlt");
   }
The problem is that this just keeps looping forever. However, for some reason, this following code works perfectly, but it fills the screen with "2"s:

Code: Select all

   while(keypressed!=1)
   {
        __asm__ __volatile__("hlt");
      puts("2");
   }
I can't get it to work unless I print the 2s.... Why is this?

Thanks,

-Stephen

Re:Strange problem with loop

Posted: Sat Apr 29, 2006 11:01 pm
by Colonel Kernel
This is just a wild guess, but did you declare the keypressed variable to be volatile?

Re:Strange problem with loop

Posted: Sat Apr 29, 2006 11:07 pm
by srg_13
Whoops... I accidentally just declared it an int.

Thanks for the quick reply!

-Stephen