https://github.com/akkartik/mu/blob/main/baremetal/102keyboard.subx
 1 # check keyboard for a key
 2 # return 0 on no keypress or unrecognized key
 3 read-key:  # kbd: (addr keyboard) -> result/eax: byte
 4     # . prologue
 5     55/push-ebp
 6     89/<- %ebp 4/r32/esp
 7     # . save registers
 8     51/push-ecx
 9     # result = 0
10     b8/copy-to-eax 0/imm32
11     # ecx = keyboard
12     8b/-> *(ebp+8) 1/r32/ecx
13     81 7/subop/compare %ecx 0/imm32
14     {
15       75/jump-if-!= break/disp8
16       # var read/ecx: byte = keyboard buffer's read index
17       8b/-> *0x7dcc 1/r32/CL  # keyboard-buffer-read
18       # var next-key/eax: byte = *(keyboard buffer + ecx)
19       8a/byte-> *(ecx+0x7dd0) 0/r32/AL  # keyboard-buffer-data
20       # if (next-key != 0) lock and remove from keyboard-buffer
21       81 7/subop/compare %eax 0/imm32
22       {
23         74/jump-if-= break/disp8
24         # TODO: add some instructions in this block to SubX if we ever want to
25         # use bootstrap on baremetal programs
26         fa/disable-interrupts
27         c6 0/subop/copy-byte *(ecx+0x7dd0) 0/imm8
28         ff 0/subop/increment *0x7dcc  # keyboard-buffer-read
29         81 4/subop/and *0x7dcc 0xf/imm32  # keyboard-buffer-read
30         fb/enable-interrupts
31       }
32       # return
33       eb $read-key:end/disp8
34     }
35     # TODO: fake keyboard
36 $read-key:end:
37     # . restore registers
38     59/pop-to-ecx
39     # . epilogue
40     89/<- %esp 5/r32/ebp
41     5d/pop-to-ebp
42     c3/return