module ModeComparator (
    a,b,m,y
);
    input[7:0] a,b;
    input m;
    output[7:0] y;

    wire agb;
    comp #(.n(8))comp_inst(.a(a),.b(b),.agb(agb),.aeb(),.alb());

    wire[7:0] max,min;
    mux_2to1 #(.n(8))mux1(.out(max),.in0(a),.in1(b),.addr(~agb));
    mux_2to1 #(.n(8))mux2(.out(min),.in0(a),.in1(b),.addr(agb));

    assign y = m ? min : max;
endmodule