Skip to main content

Counter

counter.exe is an external binary application that implements a counter on N bits. It is implemented here.

It's a convenient piece of bopkit that comes in handy when you want to go over all possible inputs for a given block. It's available from various entry points.

Built-in option in bopkit simu

Consider the circuit and.bop:

Main(a, b) = s
where
s = And(a, b);
end where;

You can simulate it for the whole range of its input using the built-in counter of bopkit simu.

$ bopkit simu and.bop --num-counter-cycles 2
Cycle | a b | s
0 | 0 0 | 0
1 | 1 0 | 0
2 | 0 1 | 0
3 | 1 1 | 1
4 | 0 0 | 0
5 | 1 0 | 0
6 | 0 1 | 0
7 | 1 1 | 1

Exported as bopkit counter

The external block is also available as bopkit counter. The simulation above can be obtained using the following equivalent command:

$ bopkit counter -N 2 --ni -c 8 |  bopkit simu and.bop
Cycle | a b | s
0 | 0 0 | 0
1 | 1 0 | 0
2 | 0 1 | 0
3 | 1 1 | 1
4 | 0 0 | 0
5 | 1 0 | 0
6 | 0 1 | 0
7 | 1 1 | 1

This time around, the input is no longer generated by simu, but read from stdin.

Used from within a circuit as an external block

Finally, the counter is exported as counter.exe to be used directly in circuits as an external block. See an example in the file out.bop:

#define N 4

Main() = out:[N]
where
out:[N] = external("counter.exe -N %{N}");
end where;
$ bopkit simu out.bop --num-cycles 8
Cycle | | out[0] out[1] out[2] out[3]
0 | | 0 0 0 0
1 | | 1 0 0 0
2 | | 0 1 0 0
3 | | 1 1 0 0
4 | | 0 0 1 0
5 | | 1 0 1 0
6 | | 0 1 1 0
7 | | 1 1 1 0