简体   繁体   中英

What is difference between assignment with and without bit selector? (e/Specman)

I'm coding in e (Specman) programming language. If I want to assign integer variable with constant, what is the difference if I use bit selector (selecting all 32 bits) or not?

I wanted to assign integer variable with negative constant in form: 32'b1... but this value was automatically cast to positive number (larger than MAX_INT) and I got the error. Then I tried using bit selector ([31:0]) on variable and assignment passed with no errors. Good number was assigned to variable. I'm not sure why is this case. What is the reason negative number is automatically cast when we don't use bit selector, and why not when we use it.

Code with error:

int_variable = 32'b111111111111111111111111

Code with no error:

int_variable[31:0] = 32'b111111111111111111111111

The docs say

In an assignment (lhs = rhs), the right-hand side (rhs) expression inherits the context of the left-hand side (lhs) expression

So your rhs expression should automatically be cast to -1 (assuming your code contains 32 or more 1's; for 31 1's you would get MAX_INT).

I don't think Specman gives an error for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM