SOGO論壇
標題:
一位元多工器 邏輯閘寫法
[列印本頁]
作者:
mm117777
時間:
2012-6-30 11:23:22
標題:
一位元多工器 邏輯閘寫法
本帖最後由 mm117777 於 2012-6-30 12:17 編輯
module mux(f, a, b, sel); // 模組
output f;
input a, b, sel; // 參數型態
and g1(f1, a, nsel), g2(f2, b, sel);
or g3(f, f1, f2);
not g4(nsel, sel); // 模組可以使用基本元件或其他模組
endmodule
Always 型的寫法
module mux(f, a, b, sel);
output f;
input a, b, sel;
reg f; // reg 型態會記住某些值,直到被某個 assign 指定改變為止
always @(a or b or sel) // 當任何變數改變的時候,會執行內部區塊
if (sel) f = a; // Always 內部的區塊採用 imperative 程式語言的寫法。
else f = b;
endmodule
Assign 型的寫法
module mux(f, a, b, sel);
output f;
input a, b, sel;
assign f = sel ? a : b; // 右邊的任何改變都會造成左邊重新賦值
endmodule
真值表寫法
primitive mux(f, a, b, sel); // 真值表型的寫法,其型態必須是 primitive。
output f;
input a, b, sel;
table
1?0 : 1; // 可以使用 ? 代表 don't care
0?0 : 0;
?11 : 1;
?01 : 0;
11? : 1; // 當 a,b 對的時候,sel 會被忽略
00? : 0;
endtable
endprimitive
歡迎光臨 SOGO論壇 (https://oursogo.com/)
Powered by OURSOGO.COM