FPGA仿真中for语句问题求解
时间:10-02
整理:3721RD
点击:
程序如下:是一个加法器
input [3:0] ain;
input [3:0] bin;
input cin;
output count;
output [3:0] sum;
assign {count,sum} = cin + ain + bin;
仿真想要ain从1-8,bin也从1-8共64中组合,for语句程序如下
initial begin ain = 0; bin = 0; cin = 0;end
always #5 cin = ~cin;
initial begin for(i=1;i<8;i=i+1) for(j=1;j<8;j=j+1) #10 bin = j; ain = i; end
initial begin $monitor($time,,, "%d + %d + %d={%d,%d}",ain,bin,cin,count,sum); #1000 $stop;end
Modelsim仿真打印结果: 0 0 + 0 + 0={0, 0}# 5 0 + 0 + 1={0, 1}# 10 0 + 1 + 0={0, 1}# 15 0 + 1 + 1={0, 2}# 20 0 + 2 + 0={0, 2}# 25 0 + 2 + 1={0, 3}# 30 0 + 3 + 0={0, 3}# 35 0 + 3 + 1={0, 4}# 40 0 + 4 + 0={0, 4}# 45 0 + 4 + 1={0, 5}# 50 0 + 5 + 0={0, 5}# 55 0 + 5 + 1={0, 6}# 60 0 + 6 + 0={0, 6}# 65 0 + 6 + 1={0, 7}# 70 0 + 7 + 0={0, 7}# 75 0 + 7 + 1={0, 8}# 80 0 + 1 + 0={0, 1}# 85 0 + 1 + 1={0, 2}# 90 0 + 2 + 0={0, 2}# 95 0 + 2 + 1={0, 3}
460 0 + 4 + 0={0, 4}# 465 0 + 4 + 1={0, 5}# 470 0 + 5 + 0={0, 5}# 475 0 + 5 + 1={0, 6}# 480 0 + 6 + 0={0, 6}# 485 0 + 6 + 1={0, 7}# 490 8 + 7 + 0={0,15}# 495 8 + 7 + 1={1, 0}# 500 8 + 7 + 0={0,15}# 505 8 + 7 + 1={1, 0}# 510 8 + 7 + 0={0,15}# 515 8 + 7 + 1={1, 0}# 520 8 + 7 + 0={0,15}# 525 8 + 7 + 1={1, 0}
960 8 + 7 + 0={0,15}# 965 8 + 7 + 1={1, 0}# 970 8 + 7 + 0={0,15}# 975 8 + 7 + 1={1, 0}# 980 8 + 7 + 0={0,15}# 985 8 + 7 + 1={1, 0}# 990 8 + 7 + 0={0,15}# 995 8 + 7 + 1={1, 0}
结果明显不是我想要的,如何才能让ain,bin分别从1-8一共有64种组合呢?
input [3:0] ain;
input [3:0] bin;
input cin;
output count;
output [3:0] sum;
assign {count,sum} = cin + ain + bin;
仿真想要ain从1-8,bin也从1-8共64中组合,for语句程序如下
initial begin ain = 0; bin = 0; cin = 0;end
always #5 cin = ~cin;
initial begin for(i=1;i<8;i=i+1) for(j=1;j<8;j=j+1) #10 bin = j; ain = i; end
initial begin $monitor($time,,, "%d + %d + %d={%d,%d}",ain,bin,cin,count,sum); #1000 $stop;end
Modelsim仿真打印结果: 0 0 + 0 + 0={0, 0}# 5 0 + 0 + 1={0, 1}# 10 0 + 1 + 0={0, 1}# 15 0 + 1 + 1={0, 2}# 20 0 + 2 + 0={0, 2}# 25 0 + 2 + 1={0, 3}# 30 0 + 3 + 0={0, 3}# 35 0 + 3 + 1={0, 4}# 40 0 + 4 + 0={0, 4}# 45 0 + 4 + 1={0, 5}# 50 0 + 5 + 0={0, 5}# 55 0 + 5 + 1={0, 6}# 60 0 + 6 + 0={0, 6}# 65 0 + 6 + 1={0, 7}# 70 0 + 7 + 0={0, 7}# 75 0 + 7 + 1={0, 8}# 80 0 + 1 + 0={0, 1}# 85 0 + 1 + 1={0, 2}# 90 0 + 2 + 0={0, 2}# 95 0 + 2 + 1={0, 3}
460 0 + 4 + 0={0, 4}# 465 0 + 4 + 1={0, 5}# 470 0 + 5 + 0={0, 5}# 475 0 + 5 + 1={0, 6}# 480 0 + 6 + 0={0, 6}# 485 0 + 6 + 1={0, 7}# 490 8 + 7 + 0={0,15}# 495 8 + 7 + 1={1, 0}# 500 8 + 7 + 0={0,15}# 505 8 + 7 + 1={1, 0}# 510 8 + 7 + 0={0,15}# 515 8 + 7 + 1={1, 0}# 520 8 + 7 + 0={0,15}# 525 8 + 7 + 1={1, 0}
960 8 + 7 + 0={0,15}# 965 8 + 7 + 1={1, 0}# 970 8 + 7 + 0={0,15}# 975 8 + 7 + 1={1, 0}# 980 8 + 7 + 0={0,15}# 985 8 + 7 + 1={1, 0}# 990 8 + 7 + 0={0,15}# 995 8 + 7 + 1={1, 0}
结果明显不是我想要的,如何才能让ain,bin分别从1-8一共有64种组合呢?