-- Pmux1.balsa: A recursive parameterised MUX definition import [balsa.types.basic] public procedure PMux ( parameter X : type; parameter n : cardinal; array n of input inp : X; output out : X ) is begin if n = 0 then print error,"Parameter n should not be zero" | n = 1 then loop select inp[0] -> inp then out <- inp end end | n = 2 then loop select inp[0] -> inp then out <- inp | inp[1] -> inp then out <- inp end end else local channel out0, out1 : X constant mid = n/2 begin PMux over type X, mid of inp[0..mid-1],out0 || PMux over type X, n-mid of inp[mid..n-1],out1 || PMux over type X, 2 of {out0,out1},out end end end -- Here is a 5-way multiplexer procedure PMux5Byte is PMux over type byte, 5 (-- procedure PMux17Byte is PMux over type byte, 17 procedure PMux4Byte is PMux over type byte, 4 procedure PMux2Byte is PMux over type byte, 2 procedure PMux1Byte is PMux over type byte, 1 --)