`include "AddVector.v"
`include "Mux.v"
module DvByTn( quotient, remainder, dividend);
output [ 2:0] quotient;
output [ 3:0] remainder;
input [ 5:0] dividend;
wire [ 6:0] sum40;
wire [ 6:0] sum20;
wire [ 5:0] sum10;
wire [ 5:0] result40;
wire [ 4:0] result20;
wire [ 3:0] result10;
AddVector #(6) av40( sum40, dividend, 6'b011000); // Subtract 40.
AddVector #(6) av20( sum20, result40, 6'b101100); // Subtract 20.
AddVector #(5) av10( sum10, result20, 5'b10110 ); // Subtract 10.
// For each mux, pass through the least significant bits of the sum if the
// most significant bit is high, which indicates the subtraction is positive;
// otherwise pass through the value before the subtraction.
Mux #(6) mx40( result40, sum40[ 6], sum40[ 5:0], dividend);
Mux #(5) mx20( result20, sum20[ 6], sum20[ 4:0], result40[ 4:0]);
Mux #(4) mx10( result10, sum10[ 5], sum10[ 3:0], result20[ 3:0]);
assign quotient[ 2] = sum40[ 6];
assign quotient[ 1] = sum20[ 6];
assign quotient[ 0] = sum10[ 5];
assign remainder = result10;
endmodule