#include "harp1.h" const dw = 8, aw = 12; const de = (1 << dw), ae = (1 << aw); void main(chan(in) STDIN : dw, chan(out) STDOUT : dw, eram data[ae] = harp1lram : dw, eram hist[de] = harp1hram : aw) { int addr, accu, x, temp; int addr_nz() = (addr != 0) : 1; void increment_address() { addr = addr + 1; } void input_to_x() { STDIN ? x; } void hist_x_to_temp() { temp = hist[x]; } void input_and_histogram() { input_to_x(); do par { { delay; input_to_x(); } { data[addr] = x; increment_address(); } { hist_x_to_temp(); hist[x] = temp + 1; } } while (addr_nz()); } void accumulate_histogram() { x = 0; do { hist_x_to_temp(); hist[x], accu, x = accu, accu + temp, x + 1; } while (x != 0); } void equalise_and_output() { do par { STDOUT ! hist[data[addr]] \\ (aw - dw); increment_address(); } while (addr_nz()); } /* Main program */ input_and_histogram(); accumulate_histogram(); equalise_and_output(); }