SOGO論壇
  登入   註冊   找回密碼
查看: 680|回覆: 0
列印 上一主題 下一主題

[技術文章] 一位元多工器 邏輯閘寫法 [複製連結]

Rank: 11Rank: 11Rank: 11Rank: 11

熱心參予論壇活動及用心回覆主題勳章 數位硬體勳章

狀態︰ 離線
跳轉到指定樓層
1
發表於 2012-6-30 11:23:22 |只看該作者 |倒序瀏覽 | x 1
本帖最後由 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
喜歡嗎?分享這篇文章給親朋好友︰
               感謝作者     

請注意︰利用多帳號發表自問自答的業配文置入性行銷廣告者,將直接禁訪或刪除帳號及全部文章!
您需要登錄後才可以回覆 登入 | 註冊


本論壇為非營利自由討論平台,所有個人言論不代表本站立場。文章內容如有涉及侵權,請通知管理人員,將立即刪除相關文章資料。侵權申訴或移除要求:abuse@oursogo.com

GMT+8, 2024-9-30 02:23

© 2004-2024 SOGO論壇 OURSOGO.COM
回頂部