A part of the PC’s BIOS data area i.e., memory at segment 0040h is used as keyboard buffer. This area also holds pointers to keyboard buffer and key status.
The keyboard buffer is organized as a circular queue. It has four 2-byte wide pointers: kbufbegin, kbufend, kbufhead and kbuftail. Here you should note one important thing: these pointers are just 2-byte wide (not 4-byte wide), which means these pointers hold only the OFFSET address (all are at segment 0040h). kbufbegin and kbufend points to the beginning and end of the keyboard buffer and these pointers do not move. Whereas the kbufhead and kbuftail points to the character on the keyboard buffer and so these pointers do move.
Keyboard buffer is a character (i.e., 1 byte wide) array. The size of the keyboard buffer may vary from system to system. Some people say that the size of the keyboard buffer is 32 bytes, which is wrong, because the size of the keyboard buffer can be changed. Keyboard buffer holds ASCII code and scan code on alternate bytes.
Whenever a key is been inputted through keyboard, it is being temporarily stored in keyboard buffer, before it is processed by the BIOS. When we try to input more keystrokes, we will get a beep sound indicating that the keyboard buffer is full. The pointer kbuftail points to the recently inputted key and the pointer kbufhead points to the key that is being currently processed. So when the keyboard buffer is empty, the pointer kbufhead and kbuftail holds the same address (i.e., points to the same data).