Strange problem with loop

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
srg_13

Strange problem with loop

Post 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
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Strange problem with loop

Post by Colonel Kernel »

This is just a wild guess, but did you declare the keypressed variable to be volatile?
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
srg_13

Re:Strange problem with loop

Post by srg_13 »

Whoops... I accidentally just declared it an int.

Thanks for the quick reply!

-Stephen
Post Reply