pranavappu007 wrote:
Code:
loop:
hlt
mov eax, [buffer_stat] ;modified by keyboard ISR to indicate new key received
cmp eax, 0
je loop
;code to read from buffer
Doing complex operations in ISRs is not a great idea, because an interrupt can get trapped while you're in the middle of handling another interrupt; so any functions you call while interrupted have to be reentrant. So yes, something like that would be a good idea.
pranavappu007 wrote:
Also because it is only monotasking I think I don't need a buffer, but just retrieve current value if needed or discard if not needed. In that cases buffer_stat itself become the scan code to read.
No, you should have a proper event queue. It doesn't matter that it's monotasking. Remember, an interrupt can trigger at any time. So, say you're performing a complex computation. The user may press two keys before you get a chance to handle either, and then the first one will be eaten.
Just a simple ring buffer should do it; nothing special. Then you can do something like:
Code:
while (true) {
Event event;
while (read_event(&event)) handle_event(event);
__asm__ volatile("hlt");
}