Circular Buffers

Background

A circular buffer implements a bounded queue, a data structure that behaves like the checkout line at the supermarket: information is added to the end of the queue and removed from the front. Unlike the supermarket line, the circular buffer has a fixed maximum capacity.

Circular buffers are usually used for communication between two sequential processes. One process, called the producer, places information into the circular buffer and the other (the consumer) takes it out. Producer and consumer may not be clearly distinguished, as in the case where a routine uses a circular buffer for temporary storage.

Interface

The cb256 module supports an arbitrary number of 256-byte circular buffers. Five basic operations can be carried out on each circular buffer: The buffer is set empty at the beginning of the communication, and thereafter the producer inserts bytes into the buffer and the consumer extracts bytes from the buffer. Insertions and extractions can occur in any order, the only restrictions being that insertions into a full buffer are ignored and extractions from an empty buffer result in undefined values.

The assembly language include file cb256.ah gives the interface specifications for all of the operations. It must be included in every assembly language file using the module. Note that the operations do not obey C interface conventions, and therefore cannot be invoked directly from a C program.

The module itself should be assembled and linked with any program that uses it.


Instructor Revision 1.9 (2003/10/17 20:13:05)