Cookbook

Creating a Four-Bit Non-Contiguous Counter

Application

This automaton is an extension of the design described in Creating a Two-Bit Output Counter. This automaton creates a four-bit counter and increments when the A symbol is seen; however, unlike in the previous design, the A symbols do not need to be consecutive (they can be separated by other symbols).

Construction

AP Workbench


Counter with four bit output and carry out four bit

C Code

#include <micron/ap/ap_defs.h>
#include <micron/ap/ap_anml.h>

int main(int argc, char* argv[]) {
    ap_anml_t anml = NULL;
    ap_anml_network_t anml_net;
    struct ap_anml_element element = {0};
    ap_anml_element_ref_t a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, 
        a13, a14, a15, a16;
    ap_anml_element_ref_t a0h, a1h, a2h, a3h, a4h, a5h, a6h, a7h, a8h, a9h, 
        a10h, a11h, a12h, a13h, a14h, a15h;
    ap_anml_element_ref_t b0, b1, b2, b3, reset;

    // Initialize the automata network
    anml = AP_CreateAnml();
    AP_CreateAutomataNetwork(anml, &anml_net, "counter_non_contig_with_4bit_display");

    // Build the network
    element.id = "a1";
    element.res_type = RT_STE;
    element.start = START_OF_DATA;
    element.symbols = "A";
    AP_AddAnmlElement(anml_net, &a1, &element);

    element.start = NO_START;
    element.id = "a2";
    AP_AddAnmlElement(anml_net, &a2, &element);
    element.id = "a3";
    AP_AddAnmlElement(anml_net, &a3, &element);
    element.id = "a4";
    AP_AddAnmlElement(anml_net, &a4, &element);
    element.id = "a5";
    AP_AddAnmlElement(anml_net, &a5, &element);
    element.id = "a6";
    AP_AddAnmlElement(anml_net, &a6, &element);
    element.id = "a7";
    AP_AddAnmlElement(anml_net, &a7, &element);
    element.id = "a8";
    AP_AddAnmlElement(anml_net, &a8, &element);
    element.id = "a9";
    AP_AddAnmlElement(anml_net, &a9, &element);
    element.id = "a10";
    AP_AddAnmlElement(anml_net, &a10, &element);
    element.id = "a11";
    AP_AddAnmlElement(anml_net, &a11, &element);
    element.id = "a12";
    AP_AddAnmlElement(anml_net, &a12, &element);
    element.id = "a13";
    AP_AddAnmlElement(anml_net, &a13, &element);
    element.id = "a14";
    AP_AddAnmlElement(anml_net, &a14, &element);
    element.id = "a15";
    AP_AddAnmlElement(anml_net, &a15, &element);
    element.id = "a16";
    element.match = 1;
    AP_AddAnmlElement(anml_net, &a16, &element);

    element.id = "a0h";
    element.start = START_OF_DATA;
    element.symbols = "[^A#]";
    element.match = 0;
    AP_AddAnmlElement(anml_net, &a0h, &element);

    element.start = NO_START;
    element.id = "a1h";
    AP_AddAnmlElement(anml_net, &a1h, &element);
    element.id = "a2h";
    AP_AddAnmlElement(anml_net, &a2h, &element);
    element.id = "a3h";
    AP_AddAnmlElement(anml_net, &a3h, &element);
    element.id = "a4h";
    AP_AddAnmlElement(anml_net, &a4h, &element);
    element.id = "a5h";
    AP_AddAnmlElement(anml_net, &a5h, &element);
    element.id = "a6h";
    AP_AddAnmlElement(anml_net, &a6h, &element);
    element.id = "a7h";
    AP_AddAnmlElement(anml_net, &a7h, &element);
    element.id = "a8h";
    AP_AddAnmlElement(anml_net, &a8h, &element);
    element.id = "a9h";
    AP_AddAnmlElement(anml_net, &a9h, &element);
    element.id = "a10h";
    AP_AddAnmlElement(anml_net, &a10h, &element);
    element.id = "a11h";
    AP_AddAnmlElement(anml_net, &a11h, &element);
    element.id = "a12h";
    AP_AddAnmlElement(anml_net, &a12h, &element);
    element.id = "a13h";
    AP_AddAnmlElement(anml_net, &a13h, &element);
    element.id = "a14h";
    AP_AddAnmlElement(anml_net, &a14h, &element);
    element.id = "a15h";
    AP_AddAnmlElement(anml_net, &a15h, &element);

    element.id = "reset";
    element.start = ALL_INPUT;
    element.symbols = "!";
    AP_AddAnmlElement(anml_net, &reset, &element);

    element.start = NO_START;
    element.symbols = "#";
    element.match = 1;
    element.id = "b0";
    AP_AddAnmlElement(anml_net, &b0, &element);
    element.id = "b1";
    AP_AddAnmlElement(anml_net, &b1, &element);
    element.id = "b2";
    AP_AddAnmlElement(anml_net, &b2, &element);
    element.id = "b3";
    AP_AddAnmlElement(anml_net, &b3, &element);

    AP_AddAnmlEdge(anml_net, a1, a2, 0);
    AP_AddAnmlEdge(anml_net, a1, a1h, 0);
    AP_AddAnmlEdge(anml_net, a1, b0, 0);

    AP_AddAnmlEdge(anml_net, a2, a3, 0);
    AP_AddAnmlEdge(anml_net, a2, a2h, 0);
    AP_AddAnmlEdge(anml_net, a2, b1, 0);

    AP_AddAnmlEdge(anml_net, a3, a4, 0);
    AP_AddAnmlEdge(anml_net, a3, a3h, 0);
    AP_AddAnmlEdge(anml_net, a3, b0, 0);
    AP_AddAnmlEdge(anml_net, a3, b1, 0);

    AP_AddAnmlEdge(anml_net, a4, a5, 0);
    AP_AddAnmlEdge(anml_net, a4, a4h, 0);
    AP_AddAnmlEdge(anml_net, a4, b2, 0);

    AP_AddAnmlEdge(anml_net, a5, a6, 0);
    AP_AddAnmlEdge(anml_net, a5, a5h, 0);
    AP_AddAnmlEdge(anml_net, a5, b0, 0);
    AP_AddAnmlEdge(anml_net, a5, b2, 0);

    AP_AddAnmlEdge(anml_net, a6, a7, 0);
    AP_AddAnmlEdge(anml_net, a6, a6h, 0);
    AP_AddAnmlEdge(anml_net, a6, b1, 0);
    AP_AddAnmlEdge(anml_net, a6, b2, 0);

    AP_AddAnmlEdge(anml_net, a7, a8, 0);
    AP_AddAnmlEdge(anml_net, a7, a7h, 0);
    AP_AddAnmlEdge(anml_net, a7, b0, 0);
    AP_AddAnmlEdge(anml_net, a7, b1, 0);
    AP_AddAnmlEdge(anml_net, a7, b2, 0);

    AP_AddAnmlEdge(anml_net, a8, a9, 0);
    AP_AddAnmlEdge(anml_net, a8, a8h, 0);
    AP_AddAnmlEdge(anml_net, a8, b3, 0);

    AP_AddAnmlEdge(anml_net, a9, a10, 0);
    AP_AddAnmlEdge(anml_net, a9, a9h, 0);
    AP_AddAnmlEdge(anml_net, a9, b0, 0);
    AP_AddAnmlEdge(anml_net, a9, b3, 0);

    AP_AddAnmlEdge(anml_net, a10, a11, 0);
    AP_AddAnmlEdge(anml_net, a10, a10h, 0);
    AP_AddAnmlEdge(anml_net, a10, b1, 0);
    AP_AddAnmlEdge(anml_net, a10, b3, 0);

    AP_AddAnmlEdge(anml_net, a11, a12, 0);
    AP_AddAnmlEdge(anml_net, a11, a11h, 0);
    AP_AddAnmlEdge(anml_net, a11, b0, 0);
    AP_AddAnmlEdge(anml_net, a11, b1, 0);
    AP_AddAnmlEdge(anml_net, a11, b3, 0);

    AP_AddAnmlEdge(anml_net, a12, a13, 0);
    AP_AddAnmlEdge(anml_net, a12, a12h, 0);
    AP_AddAnmlEdge(anml_net, a12, b2, 0);
    AP_AddAnmlEdge(anml_net, a12, b3, 0);

    AP_AddAnmlEdge(anml_net, a13, a14, 0);
    AP_AddAnmlEdge(anml_net, a13, a13h, 0);
    AP_AddAnmlEdge(anml_net, a13, b0, 0);
    AP_AddAnmlEdge(anml_net, a13, b2, 0);
    AP_AddAnmlEdge(anml_net, a13, b3, 0);

    AP_AddAnmlEdge(anml_net, a14, a15, 0);
    AP_AddAnmlEdge(anml_net, a14, a14h, 0);
    AP_AddAnmlEdge(anml_net, a14, b1, 0);
    AP_AddAnmlEdge(anml_net, a14, b2, 0);
    AP_AddAnmlEdge(anml_net, a14, b3, 0);

    AP_AddAnmlEdge(anml_net, a15, a16, 0);
    AP_AddAnmlEdge(anml_net, a15, a15h, 0);
    AP_AddAnmlEdge(anml_net, a15, b0, 0);
    AP_AddAnmlEdge(anml_net, a15, b1, 0);
    AP_AddAnmlEdge(anml_net, a15, b2, 0);
    AP_AddAnmlEdge(anml_net, a15, b3, 0);

    AP_AddAnmlEdge(anml_net, a16, a1, 0);
    AP_AddAnmlEdge(anml_net, a16, a0h, 0);

    AP_AddAnmlEdge(anml_net, a0h, a0h, 0);
    AP_AddAnmlEdge(anml_net, a0h, a1, 0);

    AP_AddAnmlEdge(anml_net, a1h, a1h, 0);
    AP_AddAnmlEdge(anml_net, a1h, a2, 0);
    AP_AddAnmlEdge(anml_net, a1h, b0, 0);

    AP_AddAnmlEdge(anml_net, a2h, a2h, 0);
    AP_AddAnmlEdge(anml_net, a2h, a3, 0);
    AP_AddAnmlEdge(anml_net, a2h, b1, 0);

    AP_AddAnmlEdge(anml_net, a3h, a3h, 0);
    AP_AddAnmlEdge(anml_net, a3h, a4, 0);
    AP_AddAnmlEdge(anml_net, a3h, b0, 0);
    AP_AddAnmlEdge(anml_net, a3h, b1, 0);

    AP_AddAnmlEdge(anml_net, a4h, a4h, 0);
    AP_AddAnmlEdge(anml_net, a4h, a5, 0);
    AP_AddAnmlEdge(anml_net, a4h, b2, 0);

    AP_AddAnmlEdge(anml_net, a5h, a5h, 0);
    AP_AddAnmlEdge(anml_net, a5h, a6, 0);
    AP_AddAnmlEdge(anml_net, a5h, b0, 0);
    AP_AddAnmlEdge(anml_net, a5h, b2, 0);

    AP_AddAnmlEdge(anml_net, a6h, a6h, 0);
    AP_AddAnmlEdge(anml_net, a6h, a7, 0);
    AP_AddAnmlEdge(anml_net, a6h, b1, 0);
    AP_AddAnmlEdge(anml_net, a6h, b2, 0);

    AP_AddAnmlEdge(anml_net, a7h, a7h, 0);
    AP_AddAnmlEdge(anml_net, a7h, a8, 0);
    AP_AddAnmlEdge(anml_net, a7h, b0, 0);
    AP_AddAnmlEdge(anml_net, a7h, b1, 0);
    AP_AddAnmlEdge(anml_net, a7h, b2, 0);

    AP_AddAnmlEdge(anml_net, a8h, a8h, 0);
    AP_AddAnmlEdge(anml_net, a8h, a9, 0);
    AP_AddAnmlEdge(anml_net, a8h, b3, 0);

    AP_AddAnmlEdge(anml_net, a9h, a9h, 0);
    AP_AddAnmlEdge(anml_net, a9h, a10, 0);
    AP_AddAnmlEdge(anml_net, a9h, b0, 0);
    AP_AddAnmlEdge(anml_net, a9h, b3, 0);

    AP_AddAnmlEdge(anml_net, a10h, a10h, 0);
    AP_AddAnmlEdge(anml_net, a10h, a11, 0);
    AP_AddAnmlEdge(anml_net, a10h, b1, 0);
    AP_AddAnmlEdge(anml_net, a10h, b3, 0);

    AP_AddAnmlEdge(anml_net, a11h, a11h, 0);
    AP_AddAnmlEdge(anml_net, a11h, a12, 0);
    AP_AddAnmlEdge(anml_net, a11h, b0, 0);
    AP_AddAnmlEdge(anml_net, a11h, b1, 0);
    AP_AddAnmlEdge(anml_net, a11h, b3, 0);

    AP_AddAnmlEdge(anml_net, a12h, a12h, 0);
    AP_AddAnmlEdge(anml_net, a12h, a13, 0);
    AP_AddAnmlEdge(anml_net, a12h, b2, 0);
    AP_AddAnmlEdge(anml_net, a12h, b3, 0);

    AP_AddAnmlEdge(anml_net, a13h, a13h, 0);
    AP_AddAnmlEdge(anml_net, a13h, a14, 0);
    AP_AddAnmlEdge(anml_net, a13h, b0, 0);
    AP_AddAnmlEdge(anml_net, a13h, b2, 0);
    AP_AddAnmlEdge(anml_net, a13h, b3, 0);

    AP_AddAnmlEdge(anml_net, a14h, a14h, 0);
    AP_AddAnmlEdge(anml_net, a14h, a15, 0);
    AP_AddAnmlEdge(anml_net, a14h, b1, 0);
    AP_AddAnmlEdge(anml_net, a14h, b2, 0);
    AP_AddAnmlEdge(anml_net, a14h, b3, 0);

    AP_AddAnmlEdge(anml_net, a15h, a15h, 0);
    AP_AddAnmlEdge(anml_net, a15h, a16, 0);
    AP_AddAnmlEdge(anml_net, a15h, b0, 0);
    AP_AddAnmlEdge(anml_net, a15h, b1, 0);
    AP_AddAnmlEdge(anml_net, a15h, b2, 0);
    AP_AddAnmlEdge(anml_net, a15h, b3, 0);

    AP_AddAnmlEdge(anml_net, reset, a1, 0);
    AP_AddAnmlEdge(anml_net, reset, a0h, 0);

    // Export the network to an ANML file
    AP_ExportAnml(anml_net, "counter_non_contig_with_4bit_display.anml", "");

    // Clean up 
    AP_DestroyAnml(anml);
    return 0;
}

Python Code

from micronap.sdk import *

def main():
    # Initialize the automata network
    A = Anml()
    AN = A.CreateAutomataNetwork(anmlId='counter_non_contig_with_4bit_display')

    # Build the network
    a1 = AN.AddSTE('A', startType=AnmlDefs.START_OF_DATA, anmlId='a1')
    a2 = AN.AddSTE('A', anmlId='a2')
    a3 = AN.AddSTE('A', anmlId='a3')
    a4 = AN.AddSTE('A', anmlId='a4')
    a5 = AN.AddSTE('A', anmlId='a5')
    a6 = AN.AddSTE('A', anmlId='a6')
    a7 = AN.AddSTE('A', anmlId='a7')
    a8 = AN.AddSTE('A', anmlId='a8')
    a9 = AN.AddSTE('A', anmlId='a9')
    a10 = AN.AddSTE('A', anmlId='a10')
    a11 = AN.AddSTE('A', anmlId='a11')
    a12 = AN.AddSTE('A', anmlId='a12')
    a13 = AN.AddSTE('A', anmlId='a13')
    a14 = AN.AddSTE('A', anmlId='a14')
    a15 = AN.AddSTE('A', anmlId='a15')
    a16 = AN.AddSTE('A', match=True, anmlId='a16')

    a0h = AN.AddSTE('[^A#]', startType=AnmlDefs.START_OF_DATA, anmlId='a0h')
    a1h = AN.AddSTE('[^A#]', anmlId='a1h')
    a2h = AN.AddSTE('[^A#]', anmlId='a2h')
    a3h = AN.AddSTE('[^A#]', anmlId='a3h')
    a4h = AN.AddSTE('[^A#]', anmlId='a4h')
    a5h = AN.AddSTE('[^A#]', anmlId='a5h')
    a6h = AN.AddSTE('[^A#]', anmlId='a6h')
    a7h = AN.AddSTE('[^A#]', anmlId='a7h')
    a8h = AN.AddSTE('[^A#]', anmlId='a8h')
    a9h = AN.AddSTE('[^A#]', anmlId='a9h')
    a10h = AN.AddSTE('[^A#]', anmlId='a10h')
    a11h = AN.AddSTE('[^A#]', anmlId='a11h')
    a12h = AN.AddSTE('[^A#]', anmlId='a12h')
    a13h = AN.AddSTE('[^A#]', anmlId='a13h')
    a14h = AN.AddSTE('[^A#]', anmlId='a14h')
    a15h = AN.AddSTE('[^A#]', anmlId='a15h')

    reset = AN.AddSTE('!', startType=AnmlDefs.ALL_INPUT, anmlId='reset')
    b0 = AN.AddSTE('#', match=True, anmlId='b0')
    b1 = AN.AddSTE('#', match=True, anmlId='b1')
    b2 = AN.AddSTE('#', match=True, anmlId='b2')
    b3 = AN.AddSTE('#', match=True, anmlId='b3')

    AN.AddAnmlEdge(a1, a2, 0)
    AN.AddAnmlEdge(a1, a1h, 0)
    AN.AddAnmlEdge(a1, b0, 0)

    AN.AddAnmlEdge(a2, a3, 0)
    AN.AddAnmlEdge(a2, a2h, 0)
    AN.AddAnmlEdge(a2, b1, 0)

    AN.AddAnmlEdge(a3, a4, 0)
    AN.AddAnmlEdge(a3, a3h, 0)
    AN.AddAnmlEdge(a3, b0, 0)
    AN.AddAnmlEdge(a3, b1, 0)

    AN.AddAnmlEdge(a4, a5, 0)
    AN.AddAnmlEdge(a4, a4h, 0)
    AN.AddAnmlEdge(a4, b2, 0)

    AN.AddAnmlEdge(a5, a6, 0)
    AN.AddAnmlEdge(a5, a5h, 0)
    AN.AddAnmlEdge(a5, b0, 0)
    AN.AddAnmlEdge(a5, b2, 0)

    AN.AddAnmlEdge(a6, a7, 0)
    AN.AddAnmlEdge(a6, a6h, 0)
    AN.AddAnmlEdge(a6, b1, 0)
    AN.AddAnmlEdge(a6, b2, 0)

    AN.AddAnmlEdge(a7, a8, 0)
    AN.AddAnmlEdge(a7, a7h, 0)
    AN.AddAnmlEdge(a7, b0, 0)
    AN.AddAnmlEdge(a7, b1, 0)
    AN.AddAnmlEdge(a7, b2, 0)

    AN.AddAnmlEdge(a8, a9, 0)
    AN.AddAnmlEdge(a8, a8h, 0)
    AN.AddAnmlEdge(a8, b3, 0)

    AN.AddAnmlEdge(a9, a10, 0)
    AN.AddAnmlEdge(a9, a9h, 0)
    AN.AddAnmlEdge(a9, b0, 0)
    AN.AddAnmlEdge(a9, b3, 0)

    AN.AddAnmlEdge(a10, a11, 0)
    AN.AddAnmlEdge(a10, a10h, 0)
    AN.AddAnmlEdge(a10, b1, 0)
    AN.AddAnmlEdge(a10, b3, 0)

    AN.AddAnmlEdge(a11, a12, 0)
    AN.AddAnmlEdge(a11, a11h, 0)
    AN.AddAnmlEdge(a11, b0, 0)
    AN.AddAnmlEdge(a11, b1, 0)
    AN.AddAnmlEdge(a11, b3, 0)

    AN.AddAnmlEdge(a12, a13, 0)
    AN.AddAnmlEdge(a12, a12h, 0)
    AN.AddAnmlEdge(a12, b2, 0)
    AN.AddAnmlEdge(a12, b3, 0)

    AN.AddAnmlEdge(a13, a14, 0)
    AN.AddAnmlEdge(a13, a13h, 0)
    AN.AddAnmlEdge(a13, b0, 0)
    AN.AddAnmlEdge(a13, b2, 0)
    AN.AddAnmlEdge(a13, b3, 0)

    AN.AddAnmlEdge(a14, a15, 0)
    AN.AddAnmlEdge(a14, a14h, 0)
    AN.AddAnmlEdge(a14, b1, 0)
    AN.AddAnmlEdge(a14, b2, 0)
    AN.AddAnmlEdge(a14, b3, 0)

    AN.AddAnmlEdge(a15, a16, 0)
    AN.AddAnmlEdge(a15, a15h, 0)
    AN.AddAnmlEdge(a15, b0, 0)
    AN.AddAnmlEdge(a15, b1, 0)
    AN.AddAnmlEdge(a15, b2, 0)
    AN.AddAnmlEdge(a15, b3, 0)

    AN.AddAnmlEdge(a16, a1, 0)
    AN.AddAnmlEdge(a16, a0h, 0)

    AN.AddAnmlEdge(a0h, a0h, 0)
    AN.AddAnmlEdge(a0h, a1, 0)

    AN.AddAnmlEdge(a1h, a1h, 0)
    AN.AddAnmlEdge(a1h, a2, 0)
    AN.AddAnmlEdge(a1h, b0, 0)

    AN.AddAnmlEdge(a2h, a2h, 0)
    AN.AddAnmlEdge(a2h, a3, 0)
    AN.AddAnmlEdge(a2h, b1, 0)

    AN.AddAnmlEdge(a3h, a3h, 0)
    AN.AddAnmlEdge(a3h, a4, 0)
    AN.AddAnmlEdge(a3h, b0, 0)
    AN.AddAnmlEdge(a3h, b1, 0)

    AN.AddAnmlEdge(a4h, a4h, 0)
    AN.AddAnmlEdge(a4h, a5, 0)
    AN.AddAnmlEdge(a4h, b2, 0)

    AN.AddAnmlEdge(a5h, a5h, 0)
    AN.AddAnmlEdge(a5h, a6, 0)
    AN.AddAnmlEdge(a5h, b0, 0)
    AN.AddAnmlEdge(a5h, b2, 0)

    AN.AddAnmlEdge(a6h, a6h, 0)
    AN.AddAnmlEdge(a6h, a7, 0)
    AN.AddAnmlEdge(a6h, b1, 0)
    AN.AddAnmlEdge(a6h, b2, 0)

    AN.AddAnmlEdge(a7h, a7h, 0)
    AN.AddAnmlEdge(a7h, a8, 0)
    AN.AddAnmlEdge(a7h, b0, 0)
    AN.AddAnmlEdge(a7h, b1, 0)
    AN.AddAnmlEdge(a7h, b2, 0)

    AN.AddAnmlEdge(a8h, a8h, 0)
    AN.AddAnmlEdge(a8h, a9, 0)
    AN.AddAnmlEdge(a8h, b3, 0)

    AN.AddAnmlEdge(a9h, a9h, 0)
    AN.AddAnmlEdge(a9h, a10, 0)
    AN.AddAnmlEdge(a9h, b0, 0)
    AN.AddAnmlEdge(a9h, b3, 0)

    AN.AddAnmlEdge(a10h, a10h, 0)
    AN.AddAnmlEdge(a10h, a11, 0)
    AN.AddAnmlEdge(a10h, b1, 0)
    AN.AddAnmlEdge(a10h, b3, 0)

    AN.AddAnmlEdge(a11h, a11h, 0)
    AN.AddAnmlEdge(a11h, a12, 0)
    AN.AddAnmlEdge(a11h, b0, 0)
    AN.AddAnmlEdge(a11h, b1, 0)
    AN.AddAnmlEdge(a11h, b3, 0)

    AN.AddAnmlEdge(a12h, a12h, 0)
    AN.AddAnmlEdge(a12h, a13, 0)
    AN.AddAnmlEdge(a12h, b2, 0)
    AN.AddAnmlEdge(a12h, b3, 0)

    AN.AddAnmlEdge(a13h, a13h, 0)
    AN.AddAnmlEdge(a13h, a14, 0)
    AN.AddAnmlEdge(a13h, b0, 0)
    AN.AddAnmlEdge(a13h, b2, 0)
    AN.AddAnmlEdge(a13h, b3, 0)

    AN.AddAnmlEdge(a14h, a14h, 0)
    AN.AddAnmlEdge(a14h, a15, 0)
    AN.AddAnmlEdge(a14h, b1, 0)
    AN.AddAnmlEdge(a14h, b2, 0)
    AN.AddAnmlEdge(a14h, b3, 0)

    AN.AddAnmlEdge(a15h, a15h, 0)
    AN.AddAnmlEdge(a15h, a16, 0)
    AN.AddAnmlEdge(a15h, b0, 0)
    AN.AddAnmlEdge(a15h, b1, 0)
    AN.AddAnmlEdge(a15h, b2, 0)
    AN.AddAnmlEdge(a15h, b3, 0)

    AN.AddAnmlEdge(reset, a1, 0)
    AN.AddAnmlEdge(reset, a0h, 0)

    # Export the network to an ANML file
    AN.ExportAnml('counter_non_contig_with_4bit_display.anml')

if __name__ == '__main__':
    main()

Operation

The significant change in this design from the Creating a Two-Bit Output Counter design is the insertion of STEs that enable the automaton to hold when a non-A symbol is seen in the input data stream. The first such STE (a0h) continuously activates STE a1 at the beginning of symbol processing. After an A symbol is seen, the automaton increments as expected.

Between each of the counting STEs (a1, a2, a3, and so forth) there are new 'hold' STEs (a1h, a2h, a3h, and so forth). Each of these STEs hold the automaton at the current count while allowing non-A symbols to pass.