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.

Dealing with signed operations in verilog.. help needed

Status
Not open for further replies.

hallovipin

Member level 1
Joined
Dec 23, 2009
Messages
40
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,638
Hi friends

module (operand_1, operand_2, sum );

input [7:0] operand_1, operand_2;
output reg [8:0] sum;
reg [8:0] difference;

initial begin
difference=0;
sum=0;
end



always @(posedge clk) begin

difference = operand_1-operand_2;
sum = sum + difference;

end


Now the question is if difference is -ve (2-3) at some point what will happen to sum. whether sum will recognize it and decrease or it will not treat difference as 2's complement and will simply increase
 

It should be noted, that Verilog also has a signed data type. But in case of the add and sub operation, it doesn't change anything. The difference between unsigned and two's complement signed is only in the interpretation of the result, the bitvector is the same. You may want to verify this by pencil and paper method.

In some cases, saturation logic may be wanted with arithmetic operations. But it's not provided by the basic add and sum operators.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top