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.

discrimination between normal and negative number stored in 2's compliment form

Status
Not open for further replies.

babaduredi

Member level 1
Member level 1
Joined
Apr 28, 2011
Messages
39
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Location
Bangalore
Visit site
Activity points
1,543
Hi,
While defining test case for a hardware, i had to use following in statement:
-8'd3;
Now this statement means -3 in decimal or 8-bit binary stored as 2's complement of binary 3, i.e 8'b1111_1101. Now when we write 8'b1111_1101, it can be -3 or (2^8)-3=253 in decimal. So how does compiler decide whether it's -3 or 253?
 

The compiler decision is based on the declaration of variable made in the startup. so if the variable x is declared as
unsigned int x; //then value is 253 or if
singned int x; // otherwise value is -3
 

The compiler decision is based on the declaration of variable made in the startup. so if the variable x is declared as
unsigned int x; //then value is 253 or if
singned int x; // otherwise value is -3
Hi, that's correct in HLLs. In verilog suppose i define x as
reg [7:0] x;
x=-8'd3;
In this case, how compiler will decide if it's 253 or -3.
 

Compiler does not care for negative number in any operation.
Designer has to take care about it. For example

a=8=4'b1000
b=-3=4'b1101 (2's complement)

if you are doing s=a+b
s=8+(-3)= 4'b1000 +4'b1101 = 5'b10101 . Discard the last 1. Because you that it was negative number.

if b was not assigned by, its output of another operation. then you should check whether it is negative number or positive number.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top