module modecomp 
title 'Control PLD for Mode-Dependent Comparator' 
"MODECOMP device 'P16V8'; 

" Input pins 
M0, M1                       pin 1, 2; 
/EQ0, /GT0, /EQ1, /GT1       pin 5, 6, 7, 8; 
/EQ2, /GT2, /EQ3, /GT3       pin 3, 4, 9, 11; 
X0, X1, Y0, Y1               pin 15, 16, 17, 18;

" Output pins 
/XEQY, /XGTY                 pin 19, 12;

equations

XEQY = EQ3 * EQ2 * EQ1 * EQ0 * /M1 * /M0 * (         " Mode 00 (32-bit)
          /X1 * /Y1 * /X0 * /Y0 +
          /X1 * /Y1 *  X0 *  Y0 +
           X1 *  Y1 * /X0 * /Y0 +
           X1 *  Y1 *  X0 *  Y0 )
     + EQ3 * EQ2 * EQ1 * EQ0 * /M1 *  M0 * (         " Mode 01 (31-bit)
        /X1 * /Y1 + X1 * Y1 )
     + EQ3 * EQ2 * EQ1 * EQ0 *  M1 * /M0;            " Mode 10 (30-bit)

XGTY = GT3 + (EQ3 * GT2) + (EQ3 * EQ2 * GT1)         " Easy cases
     + (EQ3 * EQ2 * EQ1 * GT0)                       " Covers all modes
     + EQ3 * EQ2 * EQ1 * EQ0 * /M1 *  M0 * X1 * /Y1  " Mode 01 (31-bit)
     + EQ3 * EQ2 * EQ1 * EQ0 * /M1 * /M0 * (         " Mode 00 (32-bit)
           X1 * /Y1 +
          /X1 * /Y1 *  X0 * /Y0 +                    " No special case
           X1 *  Y1 *  X0 * /Y0 );                   "  needed for 30-bit mode

end modecomp
