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.

retaining of value of an integer in Verilog

Status
Not open for further replies.

anne rachel

Junior Member level 2
Junior Member level 2
Joined
Jan 11, 2011
Messages
20
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Visit site
Activity points
1,435
Hello all,


I am unable to retain the value of the integer "result " . As soon as the first "always" block ends, the value of result is 0 as initialised but after the execution of the second "always" block, the correct value of "result" is being displayed. Can anyone help me in retaining the value of the integer "result" after execution of first "always" block ?
The following is my code for BCD to binary conversion of 136 bit in Verilog.


module one36bit_bcd_bin(bcd,bin);
input [135:0] bcd;
output reg [135:0]bin;
integer result=0;
//reg [15:0]resreg;
integer i=0;
always @ (bcd)
begin
result=(bcd[3:0]);
result=result+(bcd[7:4])*8'd10;
result=result+(bcd[11:8])*12'd100;
result=result+(bcd[15:12])*16'd1000;
result=result+(bcd[19:16])*20'd10000;
result=result+(bcd[23:20])*24'd100000;
result=result+(bcd[27:24])*28'd1000000;
result=result+(bcd[31:28])*32'd10000000;
result=result+(bcd[35:32])*36'd100000000;
result=result+(bcd[39:36])*40'd1000000000;
result=result+(bcd[43:40])*44'd10000000000;
result=result+(bcd[47:44])*48'd100000000000;
result=result+(bcd[51:48])*52'd1000000000000;
result=result+(bcd[55:52])*56'd10000000000000;
result=result+(bcd[59:56])*60'd100000000000000;
result=result+(bcd[63:60])*64'd1000000000000000;
result=result+(bcd[67:64])*68'd10000000000000000;
result=result+(bcd[71:68])*72'd100000000000000000;
result=result+(bcd[75:72])*76'd1000000000000000000;
result=result+(bcd[79:76])*80'd10000000000000000000;
result=result+(bcd[83:80])*84'd100000000000000000000;
result=result+(bcd[87:84])*88'd1000000000000000000000;
result=result+(bcd[91:88])*92'd10000000000000000000000;
result=result+(bcd[95:92])*96'd100000000000000000000000;
result=result+(bcd[99:96])*100'd1000000000000000000000000;
result=result+(bcd[103:100])*104'd10000000000000000000000000;
result=result+(bcd[107:104])*108'd100000000000000000000000000;
result=result+(bcd[111:108])*112'd1000000000000000000000000000;
result=result+(bcd[115:112])*116'd10000000000000000000000000000;
result=result+(bcd[119:116])*120'd100000000000000000000000000000;
result=result+(bcd[123:120])*124'd1000000000000000000000000000000;
result=result+(bcd[127:124])* 128'd10000000000000000000000000000000;

result=result+(bcd[131:128])*132'd100000000000000000000000000000000;
result=result+(bcd[135:132])*136'd1000000000000000000000000000000000;
$display("result =%d",result);
end
always @(bcd)
//initial
begin
$display("result =%d",result);
while(result>0)
begin
bin=result%2;
result=result/2;
i=i+1;
end
if(i<135)
begin
while(i<=135)
begin
bin=0;
i=i+1;
end
end
end
endmodule



Thanks in advance!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top