多工器

Verilog

基本語法

型態

全域變數

基本元件

多樣的寫法

指定

assign

always

initial

運算式

分枝

迴圈

模組

函數

Task

陣列

輸出入

觀察

真值表

測試程式

訊息顯示

注意事項

模擬程序

硬體工程

程式範例

Xor

Xor3

全加器

加法器

加減器

快速加法器

乘法器

ALU

閂鎖器

脈衝偵測

計數器

多工器

暫存器群

記憶體

延遲問題

浮點數

狀態機

程式計數器

CPU0-Mini

CPU0

pipeline

工具

QuartusII

Icarus

Veritek

訊息

相關網站

參考文獻

最新修改

簡體版

English

一位元多工器

邏輯閘寫法

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

參考來源

  1. The Verilog Language (PDF Slides 80p)

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License