-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2sComp.v
More file actions
50 lines (42 loc) · 1002 Bytes
/
2sComp.v
File metadata and controls
50 lines (42 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 20.02.2024 15:49:46
// Design Name:
// Module Name: 2sComp
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module twos_comp_32bit(in,out,en);
//variable declaration for 32bit twos complement calculator
input en;
input [31:0]in;
output reg [31:0]out;
reg [31:0]comp;
integer i;
//logic block
//when en == 1 -- out = 2's comp of inp
//when en == 0 -- out = inp
always @(in,en)
begin
if(en)
begin
for(i = 0; i<32 ; i = i+1)
comp[i] = !in[i];
out = comp + 1;
end
else
out = in;
end
endmodule