veriloghdl循环语法

veriloghdl循环语法

ID:16295043

大小:30.50 KB

页数:4页

时间:2018-08-09

veriloghdl循环语法_第1页
veriloghdl循环语法_第2页
veriloghdl循环语法_第3页
veriloghdl循环语法_第4页
资源描述:

《veriloghdl循环语法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、WhileLoop//Illustration1:Incrementcountfrom0to127.Exitatcount128.//Displaythecountvariable.integercount;initialbegincount=0;while(count<128)//Executelooptillcountis127.//exitatcount128begin$display("Count=%d",count);count=count+1;endend//Illustration2:Findthefirs

2、tbitwithavalue1inflag(vectorvariable)'defineTRUE1'b1';'defineFALSE1'b0;reg[15:0]flag;integeri;//integertokeepcountregcontinue;initialbeginflag=16'b0010_0000_0000_0000;i=0;continue='TRUE;while((i<16)&&continue)//Multipleconditionsusingoperators.beginif(flag[i])beg

3、in$display("EncounteredaTRUEbitatelementnumber%d",i);continue='FALSE;endi=i+1;endendForLoopintegercount;initialfor(count=0;count<128;count=count+1)$display("Count=%d",count);forloopscanalsobeusedtoinitializeanarrayormemory,asshownbelow.//Initializearrayelements'd

4、efineMAX_STATES32integerstate[0:'MAX_STATES-1];//Integerarraystatewithelements0:31integeri;initialbeginfor(i=0;i<32;i=i+2)//initializeallevenlocationswith0state[i]=0;for(i=1;i<32;i=i+2)//initializealloddlocationswith1state[i]=1;endRepeatLoop//Illustration1:increm

5、entanddisplaycountfrom0to127integercount;initialbegincount=0;repeat(128)begin$display("Count=%d",count);count=count+1;endend//Illustration2:Databuffermoduleexample//Afteritreceivesadata_startsignal.//Readsdatafornext8cycles.moduledata_buffer(data_start,data,clock

6、);parametercycles=8;inputdata_start;input[15:0]data;inputclock;reg[15:0]buffer[0:7];integeri;always@(posedgeclock)beginif(data_start)//datastartsignalistruebegini=0;repeat(cycles)//Storedataattheposedgeofnext8clock//cyclesbegin@(posedgeclock)buffer[i]=data;//wait

7、stillnext//posedgetolatchdatai=i+1;endendendendmoduleForeverloop//Example1:Clockgeneration//Useforeverloopinsteadofalwaysblockregclock;initialbeginclock=1'b0;forever#10clock=~clock;//Clockwithperiodof20unitsend//Example2:Synchronizetworegistervaluesateverypositiv

8、eedgeof//clockregclock;regx,y;initialforever@(posedgeclock)x=y;

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。