在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 19867|回复: 19

[原创] Verilog for循环仿真问题

[复制链接]
发表于 2010-1-27 12:54:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
小弟仿真遇到点问题。请各位大侠指教。

下面是本人仿真的程序。
初module 和  endmodule  两句是我自己添加的,中间部分是夏宇闻老师《verilog数字系统设计教程》

中for 循环部分的例句。

在quartus II 中仿真时一直报错。

Error (10170): Verilog hdl syntax error at selector.v(8) near text "begin";  expecting an

identifier ("begin" is a reserved keyword ), or "endmodule", or a parallel statement
Error (10112): Ignored design unit "mux" at selector.v(1) due to previous errors




module mux(result,opa,opb);
parameter  size = 8, longsize = 16;

reg[size:1] opa, opb;

reg[longsize:1] result;

begin:mult

    integer bindex;

    result=0;

    for( bindex=1; bindex<=size; bindex=bindex+1 )

if(opb[bindex])

  result = result + (opa<<(bindex-1));

end

endmodule
发表于 2010-1-27 13:18:39 | 显示全部楼层
verilog中所有的赋值语句,除了assign结构以外,都必须放在initial和always的结构里面,begin和end 是用来充当这两种结构的起止符,你的例子需要更改如下:
module mux(result,opa,opb);
parameter  size = 8, longsize = 16;

reg[size:1] opa, opb;

reg[longsize:1] result;

initial begin:mult

    integer bindex;

    result=0;

    for( bindex=1; bindex<=size; bindex=bindex+1 )

if(opb[bindex])

  result = result + (opa<<(bindex-1));

end

endmodule
=========================
另外,for循环语句不可综合,只能用来产生激励(generate语句的for结构可综合)
发表于 2010-1-27 14:08:27 | 显示全部楼层
顶楼上
发表于 2010-1-27 17:27:08 | 显示全部楼层
me too
 楼主| 发表于 2010-1-27 18:28:34 | 显示全部楼层
按照2楼的方法进行仿真,还是报错

如下:


Info: Found 1 design units, including 1 entities, in source file mux.v
        Info: Found entity 1: mux
Error (10158): Verilog HDL Module Declaration error at mux.v(1): port "result" is not declared as port
Error (10158): Verilog HDL Module Declaration error at mux.v(1): port "opa" is not declared as port
Error (10158): Verilog HDL Module Declaration error at mux.v(1): port "opb" is not declared as port
Error: Quartus II Analysis & Synthesis was unsuccessful. 3 errors, 1 warning
        Error: Peak virtual memory: 154 megabytes
        Error: Processing ended: Wed Jan 27 18:35:42 2010
        Error: Elapsed time: 00:00:02
        Error: Total CPU time (on all processors): 00:00:02
发表于 2010-1-27 20:55:01 | 显示全部楼层
没有端口声明啊
发表于 2010-1-28 10:35:17 | 显示全部楼层
晕,没仔细看。
你这个例子既然只能用来产生激励,它本身就应该没有端口,所以你的例子再更改一下:
module mux();

=======
把端口声明为空。
发表于 2010-1-28 10:50:35 | 显示全部楼层
看看,感谢分享
 楼主| 发表于 2010-1-28 12:50:17 | 显示全部楼层
我的本意是用这个程序去实现以个乘法的动作。

现在改过后,好像还是有点问题。

我用的是quartus II 8.0 ,error里提示说,此段程序不包含logic。
发表于 2010-1-28 14:40:30 | 显示全部楼层
module mult_8(x,y,result);
input [7:0] x,y;
output [15:0] result;

assign result=x*y;

endmodule

//乘法器,不用搞那么复杂
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /3 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-17 03:30 , Processed in 0.036162 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表