How to define the size of number with a macro experssion?

M

MYH

Guest
Hi.

How to specify the size of a number by a define macro expression?
For example:
---------------------------------------------------------------------
`define m 1
`define n (`m+1)

// The following line will get a compilation error in ModelSim.
// Because (1+1)'b10 is a error syntax.
reg [1:0] p = `n'b10;
---------------------------------------------------------------------

But if you change the n to `m+1, that is:
---------------------------------------------------------------------
`define m 1
`define n `m+1
---------------------------------------------------------------------
Then `n'b10 will expand to `m+1'b10.
And `m+1'b10 will expand to 1+1'b10 (This is a 32bit 1 plus a 1bit 0!)
But I really want this number: 2'b10

How do I solve this problem?

Thanks.
 

Welcome to EDABoard.com

Sponsor

Back
Top