Introduction
Multiplication in digital design can be efficiently performed using left shift operators in Verilog, especially to minimize code and calculations. In this blog, we’ll multiply two numbers, a = 63 and b = 7, using the left shift method. We’ll also include a second example, 63 ×10, to ensure clarity. We select (a) as the number requiring more bits (63 needs 6 bits, while 7 needs 3 bits), following the convention to optimize the process.
Step 1: Select Numbers (a) and (b)
We are given:
- , which requires 6 bits (since
a = 63
)2).63 = (111111
- , which requires 3 bits (since
b = 7
7 = (111)2).
We choose and because (a) requires more bits, reducing the number of iterations. We’ll also compute as a second example, where (10) requires 4 bits (
a = 63
b = 7
63×10
10 = (1010)2).
Step 2: Convert (b) to Binary and Identify True Values
Example 1:
Convert to binary:
b = 7
Convert
b = 7
7 = (111)2
Identify positions with a true value (1):
- Position 2 (): 1 (true)
2^2
- Position 1 (): 1 (true)
2^1
- Position 0 (): 1 (true)
2^0
True values are at , , and .
2^2
2^1
2^0
Example 2:
Convert to binary:
b = 10
Convert
b = 10
- .
10 = 1010_2
Identify positions with a true value (1):
- Position 3 (): 1 (true)
2^3
- Position 2 (): 0 (false)
2^2
- Position 1 (): 1 (true)
2^1
- Position 0 (): 0 (false)
2^0
True values are at and .
2^3
2^1
Step 3: Multiply Using Left Shifts
Example 1:
For each position where has a 1, left shift by that position’s power and add the results:
63×7=?
For each position where
b = 7
a = 63
- Position 2 ():
2^2
63 << 2
- Position 1 ():
2^1
63 << 1
- Position 0 ():
2^0
63 << 0
The multiplication result is:
Result = (63 << 2) + (63 << 1) + (63 << 0)
Calculate:
63 << 2 = 252
63 << 1 = 126
63 << 0 = 63
Add them: 252 + 126 + 63 = 441
So, .
63×7 = 441
Example 2:
For each position where has a 1, left shift by that position’s power and add the results:
63×10
For each position where
b = 10
a = 63
- Position 3 ():
2^3
63 << 3
- Position 1 ():
2^1
63 << 1
The multiplication result is:
Result = (63 << 3) + (63 << 1)
Calculate:
63 << 3 = 504
63 << 1 = 126
Add them: 504 + 126 = 630
So, .
63×10 = 630
Verilog Code
module top;
integer result;
initial begin
// multiplication of 63 and 7
result = (63<<2) + (63<<1) + (63<<0);
$display ("==> 63×7:%0d",result);
// multiplication of 63 and 10
result = (63<<3) + (63<<1);
$display ("==> 63×10:%0d",result);
end
endmodule
module top;
integer result;
initial begin
// multiplication of 63 and 7
result = (63<<2) + (63<<1) + (63<<0);
$display ("==> 63×7:%0d",result);
// multiplication of 63 and 10
result = (63<<3) + (63<<1);
$display ("==> 63×10:%0d",result);
end
endmodule
Output
Running the above code produces the following results
==> 63x7:441
==> 63x10:630
Running the above code produces the following results
==> 63x7:441
==> 63x10:630
0 Comments