-- count10e.balsa: an aysnchronous up/down loadable decade counter -- optimised version import [balsa.types.basic] public type C_size is nibble constant max_count = 9 type dir is enumeration down, up end type mode is enumeration load, count end type In_bundle is record ld_data : C_size ; mode : mode; dir : dir end procedure updown10 (input in_sigs: In_bundle; output count: C_size) is local variable count_reg : C_size variable tmp : C_size begin loop select in_sigs then if in_sigs.mode = load then count_reg := in_sigs.ld_data else case in_sigs.dir of down then -- counting down if count_reg /= 0 then tmp := (count_reg - 1 as C_size) else tmp := max_count end | up then -- counting up if count_reg /= max_count then tmp := (count_reg + 1 as C_size) else tmp := 0 end end || count <- count_reg ; -- outut assignment moved to here count_reg := tmp end -- end if end -- complete select H/S end -- loop end end