Node 017
This node reads bit stream from 117, removes stuffing bits, and sends data downstream. It passes tokens unmodified.
Source code
017 bit stripping
arm 00 @p !p ; 6 , cnt 02 0 ,
strp 03 b-b if a push @p 2 'cnt , a! @ -1 . + if ! pop a! ;
then drop arm pop a! @b drop ; then arm ;
go 0E @b -if ! arm go ; then strp ! go ; 13
init right a! down b! go ; 17
6 d 8 r 0 ether
arm 00 @p !p ; 6 , cnt 02 0 ,
strp 03 b-b if a push @p 2 'cnt , a! @ -1 . + if ! pop a! ;
then drop arm pop a! @b drop ; then arm ;
go 0E @b -if ! arm go ; then strp ! go ; 13
init right a! down b! go ; 17
6 d 8 r 0 ether
Definitions
- arm
- Set counter cnt to initial value 6, i.e. number of one bits before stuffing bit comes.
- cnt
- Address of the counter of one bits to go before stuffing bit comes.
- strp
- Test the bit b; if one then decrement counter cnt, and if zero after decrementing then rearm the counter and drop the following bit (it is the stuffing bit). Else return to go to send this bit downstream. If bit is zero just rearm and return to go.
- go
- Read from DOWN and pass tokens (negative numbers) downstream, while rearming the counter cnt. If not token the bit is sent to strp and the result of stripping is sent downstream. Jump to go again.
- init
- Set A and B, and jump to go.
Description
This code reads bits from node 117), and counts one bits (encoded as 80). When six consecutive one bits has been counted, we know that a stuffing zero bit is coming and we drop it from the stream. The stuffing bit removal is carried out by word strp, so that word go simply reads a bit from node 117, calls strp to remove zero bit if needed, and then passes the bit read to RIGHT to node 016. Thus, from the point of view of neighbor nodes node 017 looks like a simple wire node.
Notice also that each zero data bit rearms the counter cnt, same as tokens (negative numbers), which are passed automatically from DOWN to RIGHT.