[SOLVED] Reading negative hex values in Verilog!Plz HELP

Status
Not open for further replies.

UFK

Member level 3
Joined
Mar 8, 2010
Messages
60
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Pakistan
Activity points
1,728
Hi All

In my code im using $readmemh to read hex values from a text file in which alot of the values are negative. Verilog is treating them as positive and returning erroneous results. Can someone please help me deal with this problem? I really need to figure out a way to recognize these negative hex values.
Please help
 

When dealing with negative numbers in verilog (either decimal or hex) you must indicate explicitly that you are using signed numbers. To do that you just have to declare your variables as signed:

"reg signed [7:0] var"

Do the same for input or output signals:

"input signed [7:0] var"
 

Thankyou so much.

I tried what u suggested but it still wont work correctly for neg values.
I am posting my code below along with the text file its supposed to read. Perhaps you could run it to see what can be fixed in it.

1. This code should compare text file values with the constant T.
2. If greater than T, then move to LSP else do nothing

The code works fine if text file has positive hex values only, but with neg as in my case its not giving correct results.

My code is


and the text file D16.txt is

12F2
FFFFFD3E
FFFFFF78
FF

Thanks alot in advance. And thankyou for all the previous help too.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…