Close

tapes and loops

A project log for Jelly

A minimal DIY 8-bit CPU made with TTL chips, to perform native brainfu*k language, extended to use three sequential access tapes.

alvaro-barcellosAlvaro Barcellos 08/13/2022 at 23:470 Comments

Jelly uses tapes. Sequential tapes and only two types of loops:

One checks if  data value is zero then moves forward until matched, other checks if  data value is not zero then moves backward until matched.

All loops must be running by compare the value at tape with [ and ] and increment or decrement a counter, forward or backward a step, until counter is zero.

As pseudo code shows, both loops only differs at forward and backward move.

By using a byte as counter, a maximum nested loops is 255.

how make nested [ and ] ?

// for [
cnt=0;
do {
    if (*dp == ‘[‘ ) cnt++;
    if (*dp == ‘]’ ) cnt--;
    dp++;
    }while (cnt);

// for ]
cnt=0;
do {
    if (*dp == ‘]‘ ) cnt++;
    if (*dp == ‘[’ ) cnt--;
    dp--;
    }while (cnt);

Discussions