divider circuits morris mano
If it is unsigned number, shift the dividend left by divider. something like this;
wire [4:0] results;
assign results = dividend << divider;
if it is signed number, then it is a bit more complicated. Do something like this;
module div(a,b,d);
input [3:0] a,b;
output [7:0] d;
reg [3:0] dvd,dvr,not_dvr;
reg [7:0] d;
reg [3:0] quo,rem;
reg sign;
integer i;
always @ ( * )
begin
if ( a[3] == 1'b1 ) // Changing the 4-bit signed to unsigned, for both, the divisor and the dividend.
dvd = ~a + 4'b1;
else
dvd = a;
if ( b[3] == 1'b1 )
dvr = ~b + 4'b1;
else
dvr = b;
not_dvr = ~dvr + 4'b1;
sign = a[3] ^ b[3]; // sign bit for the product.
if (b==4'b0) // For the case where the divisor is 0,
//we make the quo & rem both zero.
begin
quo = 1'b0;
rem = a;
end
else
begin
quo = 1'b0; // set the quotient to 0.
for ( i=1; i<=8; i=i+1) // actual division division algorithm.
if (dvd >= dvr)
begin
dvd = dvd + not_dvr;
quo = i;
end
rem = dvd;
end
if ( a[3] == 1'b1 ) // same signs
rem = ~rem + 4'b1;
if ( sign == 1'b1 ) // quotient is positive only if both the
//dividend & the divisor have the same sign.
quo = ~quo + 4'b1;
d = \{ quo, rem \}; // Concatenating to get the result.
end
endmodule