Verilog HDL——循环语句
生活随笔
收集整理的這篇文章主要介紹了
Verilog HDL——循环语句
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
循環語句
Verilog HDL中4種循環語句
for循環
語法:
for(循環變量賦初值;循環執行條件;循環變量增值)
循環體語句的語句塊;
while循環
while表達式在開始不為真(假、x、z)則語句不被執行。
/* while 無符號數乘法器 mult_8b_while */ module mult_8b_while( a,b,q);parameter bsize =8; input[bsize:0]a,b; output[2*bsize-1:0]q;reg[2*bsize:0]q,a_t; reg[bsize-1:0]b_t; reg[bsize-1:0]cnt;always@(a or b)beginq = 0;a_t ={{bsize[0]},a};//{0000 0000 a}b_t = b;cnt = bsize;while(cnt>0)beginif(b_t[0])beginq = q + a_t;endelse beginq = q;endcnt = cnt - 1;a_t = a_t<<1;b_t = b_t>>1;end endendmodulerepeat循環
repeat循環計數表達式的值不確定時(x或z),則循環次數為0。
/* 8比特數據乘法 mult_8b_repeat */module mult_8b_repeat( a,b,q );parameter bsize = 8;input[bsize-1:0]a,b;output[2*bsize-1:0]q;reg[2*bsize-1:0]q,a_t;reg[bsize-1:0]b_t;always@(a or b)beginq = 0;a_t = {{bsize[0]},a};b_t = b;repeat(bsize) beginif(b_t[0])beginq = q + a_t;endelse beginq = q;enda_t = a_t<<1;b_t = b_t>>1;endend endmodule輸出q為a、b相乘:
總結
以上是生活随笔為你收集整理的Verilog HDL——循环语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Intel汇编指令在线手册
- 下一篇: 单链表之寻找中间结点