www.pudn.com > x86.rar > twos_compl.v, change:2007-12-05,size:1854b


 
module twosComp8(out,in); 
input [7:0] in; 
output [7:0] out; 
reg [7:0] out; 
reg convert; 
reg [3:0]i; 
 
always @(in) 
begin 
  
 out=~in; 
 convert=1; 
for(i=0;i<8;i=i+1) 
begin 
	if(convert) 
	begin 
		if(!out[i]) 
		begin 
			convert=~convert; 
		end 
		out[i]=~out[i]; 
	end 
 
end 
end 
endmodule 
 
 
module twosComp16(out,in); 
input [15:0] in; 
output [15:0] out; 
reg [15:0] out; 
reg convert; 
reg [5:0] i; 
always @(in) 
begin 
  
 out=~in; 
convert=1; 
for(i=0;i<16;i=i+1) 
begin 
	if(convert) 
	begin 
		if(!out[i]) 
		begin 
			convert=~convert; 
		end 
		out[i]=~out[i]; 
	end 
end 
end 
endmodule 
 
 
module twosComp(out,in); 
input [31:0] in; 
output [31:0] out; 
reg [31:0] out; 
reg convert; 
reg [6:0] i; 
 
always @(in) 
begin 
  
 out=~in; 
convert=1; 
for(i=0;i<32;i=i+1) 
begin 
	if(convert) 
	begin 
		if(!out[i]) 
		begin 
			convert=~convert; 
		end 
		out[i]=~out[i]; 
	end 
end 
end 
endmodule 
 
 
 
module twosComp64(out,in); 
input [63:0] in; 
output [63:0] out; 
reg [63:0] out; 
reg convert; 
reg [7:0] i; 
 
always @(in) 
begin 
  
 out=~in; 
convert=1; 
for(i=0;i<64;i=i+1) 
begin 
	if(convert) 
	begin 
		if(!out[i]) 
		begin 
			convert=~convert; 
		end 
		out[i]=~out[i]; 
	end 
end 
end 
 
endmodule 
 
 
module twosComp128(out,in); 
input [127:0] in; 
output [127:0] out; 
reg [127:0] out; 
reg convert; 
reg [15:0] i; 
 
always @(in) 
begin 
  
 out=~in; 
convert=1; 
for(i=0;i<128;i=i+1) 
begin 
	if(convert) 
	begin 
		if(!out[i]) 
			convert=~convert; 
		out[i]=~out[i]; 
	end 
end 
end 
 
endmodule 
 
 
module twosComp65(out,in); 
input [64:0] in; 
output [64:0] out; 
reg [64:0] out; 
reg convert; 
reg [7:0] i; 
 
always @(in) 
begin 
  
 out=~in; 
convert=1; 
for(i=0;i<=64;i=i+1) 
begin 
	if(convert) 
	begin 
		if(!out[i]) 
			convert=~convert; 
		out[i]=~out[i]; 
	end 
end 
end 
 
endmodule