How does Cyclic Buffer work?

Chapter 2 Cyclic Buffer Animation
Chapter 2.1 Introduction

You will see what a wonderful tool animation is. Instead of writing that the contents of register A will be entered into register B provided that… etc., you just click on the clock and examine the digital circuit yourself! You will feel like Monsieur Jourdain from Molière who discovered that he had been speaking prose all his life.
I recommend turning on the audio.

Chapter 2. 2 Very important!!! How to enter and exit each animation
You trigger the animation by clicking the word ANIMATION. located under Fig.2-2. You then enter the appropriate SCRATCH server page but at the same time exit this course page! Therefore, when everything is clear, go back by clicking the classic Windows button with the “return to previous page” arrow.


Fig. 2-1
How to return from animation to the course.

Chapter 2.3 Cyclic Buffer Animation
Click the blue tekst ANIMATION under Fig. 2-2 and then the green flag to set the initial state.

Fig. 2-2
Cyclic Buffer filling and emptying cycle ANIMATION
By clicking on the clock-zegar, observe how the text “Alice has a cat” is entered from UDR via the Cyclic Buffer into RAM.
You will notice that:
– during the Cyclic Buffer Filling cycle, subsequent characters bytes from UDR are introduced into the head of the snake H–>snake increments to the right
– during the Cyclic Buffer Flushing cycle, the earliest bytes entered into the Cyclic Buffer are “swept” from the tail of the T snake to the RAM memory -> the snake “shortens” to the right.
– Change the cycle from Filling to Emptying when a space character appears in the H head
– Cycle change from Empty to Fill when the buffer is empty. In other words when T=H or “the death of the snake”
The “texts in clouds” alongside the animation may also be helpful in the analysis.

Chhapter 2.4 Notes for the developer
Using the above information, you can write a program in assembler or another language (e.g. C++) for a specific microprocessor system. Here, for educational reasons, an 8-byte buffer was used. There is no problem with the text “Ala has a cat”, but with e.g. “Aleksandra has a cat” the system will go crazy. The snake will start eating its tail. This can be remedied very easily. The size of the Cyclic Buffer should be increased, e.g. to 32 bytes. There are rarely english words larger than 32 letters in the and the system should work properly. Regardless, the condition when T=H in the buffer filling cycle means “eating the tail”. You should then write a program to handle this unfavorable phenomenon, e.g. blinking of the lamp in the simplest case. In turn, the T=H state in the buffer flush cycle is “buffer empty”.
The main task of the programmer is to select the appropriate moment for switching the filling/emptying cycle.
In the case of a cycle transition from emptying the buffer to filling the buffer, the matter is probably obvious. This is the T=H state in the filling cycle. The buffer is then empty, or in other words the snake has no head because it overlaps the tail –>T=H.
The transition from buffer filling to buffer emptying is different. This is where the programmer can mess around. In our example, this signal was the space character. And you can do it differently. For example, a signal of an impending buffer overflow. For example, when there are already 30 bytes in the 32-byte buffer. Or else…


Scroll to Top