Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Any Shortcut for assigning msb of a product to a variable

Status
Not open for further replies.

rahdirs

Advanced Member level 1
Joined
May 22, 2013
Messages
424
Helped
93
Reputation
192
Reaction score
91
Trophy points
1,308
Location
Mordor
Activity points
4,492
Hi,

I am multiplying two variables (16 bit) in verilog, so the maximum number of bits of the product is 32 bits. Is there any shortcut to assign the msb 16 bits to a variable ?

Code:
	parameter a = 16'hABCD;
	parameter b = 16'hFFFF;
	wire [15:0] c;

	assign c = a*b;

c will be assigned the 16 lsb bits, is there any shorter way of doing this without declaring a 32 bit variable as in,

Code:
        wire [31:0] product
	wire [15:0] c;

	assign product = a*b;
        assign c = product[31:16]
 

untested but the following might work:

Code Verilog - [expand]
1
assign c = (a*b) >> 16;



the >> will be performed prior to the assignment.
 

I can test this tomorrow when I'm sitting at my desk but you might be able to do this:

Code:
assign c = 16'(32'(a*b)[31:16]);

I am unsure why you need to avoid two extra lines to accomplish this? I don't know if the above will synthesize.
 

Hi,

Are the input values "signed" or "unsigned"?

Klaus
 

In SystemVerilog, you can do select of a concatenation:

Code:
assign c = {a*b}[31:16];
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top