% accumulate the number of one's in the input bytes Aug 20'00 % SUBDESIGN BITSUM (CP, /CLR, % clears the accumulator % D[7..0] % the input bits % :INPUT; ACCUM[1..0] % the number of accumulated bits 0,1,2,>2 % :OUTPUT;) VARIABLE SL[2..0] :LCELL; % the bit sums for the lower 4 bits % SM[2..0] :LCELL; % the bit sums for the upper 4 bits % SUM[2..0] :LCELL; % the bit sums for the 8 bits % GT2 :LCELL; % greater than 2 within 8 bits % QONE :DFF ; % one accumulated bit % QTWO :DFF ; % two accumulated bits % QGTT :DFF ; % greater than two accumulated bits % BEGIN % sum the bits: % SL0 = !D0 & !D1 & !D2 & !D3 ; SL1 = D0 & !D1 & !D2 & !D3 # !D0 & D1 & !D2 & !D3 # !D0 & !D1 & D2 & !D3 # !D0 & !D1 & !D2 & D3 ; SL2 = D0 & D1 & !D2 & !D3 # !D0 & D1 & D2 & !D3 # !D0 & !D1 & D2 & D3 # D0 & !D1 & D2 & !D3 # !D0 & D1 & !D2 & D3 # D0 & !D1 & !D2 & D3 ; SM0 = !D4 & !D5 & !D6 & !D7 ; SM1 = D4 & !D5 & !D6 & !D7 # !D4 & D5 & !D6 & !D7 # !D4 & !D5 & D6 & !D7 # !D4 & !D5 & !D6 & D7 ; SM2 = D4 & D5 & !D6 & !D7 # !D4 & D5 & D6 & !D7 # !D4 & !D5 & D6 & D7 # D4 & !D5 & D6 & !D7 # !D4 & D5 & !D6 & D7 # D4 & !D5 & !D6 & D7 ; SUM0 = SL0 & SM0 ; SUM1 = SL1 & SM0 # SM1 & SL0 ; SUM2 = SL2 & SM0 # SM2 & SL0 # SL1 & SM1 ; GT2 = !SUM0 & !SUM1 & !SUM2 ; % accumulate and code the bit sums: % QONE.D = SUM1 # QONE ; QTWO.D = SUM1 & QONE # SUM2 # QTWO ; QGTT.D = QTWO & (SUM1 # SUM2) # QONE & SUM2 # GT2 # QGTT ; ACCUM[0] = QONE & !QTWO # QGTT ; ACCUM[1] = QTWO # QGTT ; % clocks and clears: % QONE.CLRN = /CLR ; QTWO.CLRN = /CLR ; QGTT.CLRN = /CLR ; QONE.CLK = CP ; QTWO.CLK = CP ; QGTT.CLK = CP ; END;