Question

How do you multiply a binary number by ten in verilog? Is it as simple as

reg [7:0] a,b;
reg[31:0] p;
b= 8'b00001001;
p=a*b;

Upgraded to windows 8 and my xilinx is working atm. Need to know asap for planning stage.

Was it helpful?

Solution

Nearly - 10 in binary is 1010! For multiplying two 8-bit numbers, you'll only need 16 bits for the result, so reg [15:0] p would do. What about:

 always @( a )
     p = a * 8'd10; 

or

wire [13:0] p;
assign p = a * 4'd10;

OTHER TIPS

I'm not sure how good the HDL synthesis tools are at converting multiplies to bit shifts. I wouldn't want to synthesise a multiplier for this code by accident (even your CPU is unlikely to use a multiply for this).

wire [7:0] a;
wire [11:0] shift2;
wire [11:0] shift1;
wire [11:0] result;

assign shift2 = a << 3; // a * 8
assign shift1 = a << 1; // a * 2
assign result = shift2 + shift1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top