Re: [myhdl-list] intbv addition
Brought to you by:
jandecaluwe
From: Christopher L. F. <chr...@gm...> - 2009-06-06 16:34:25
|
> a=intbv(3)[2:] > b=intbv(1)[2:] > c=a+b > > the sum (c) is not 'intbv' class, its 'long' if I'm not mistaken. How > can we get the sum to be 'intbv' of the same bitwidth (in this case > 2)? > > You would want to do the following (which is the same as other HDLs) a = intbv(3)[2:] b = intbv(1)[2:] c = intbv(1)[2:] c[:] = a+b As you noticed, the result of the intbv math operations returns an integer (long). What you need to do is create an intbv type for the left hand side of the operation. For the above example you will get an error. The intbv will check the limits of addition. You will need to create "c" to be large enough for the result of the addition. c = intbv(1)[3:] Hope that helps, for more background information see Jan's essay on constraint integer, http://www.jandecaluwe.com/hdldesign/counting.html. Chris |