# Verilog 的基本介紹 ###### tags: `verilog` `digital design` `邏輯設計` `邏設` [TOC] ## English Version [English Version](https://hackmd.io/@dppa1008/SJeRLbkwI) ## Something You have to know Verilog 跟之前各位所學的 C language 不一樣,屬於硬體語言,他的思考邏輯跟軟體不一樣,<font color=#bf2222>不能用軟體的思維來寫硬體</font>,因此,我們將快速地帶大家了解什麼是硬體語言 Verilog。 ## 基本架構 ```clike= module module_name (input/output port); 1. define the input/output 2. define some parameters 3. your design endmodule ``` ## module 1. verilog 的主要單元架構。所有的 verilog 程式都是由許多的 module 組成。 2. 如果用 c 語言來比喻, module 就像是 function 一樣的存在。 3. module_name:每一個 module 都有自己的名稱,不能跟他人重複。 4. module 的 input 跟 output 可能來自<font color=#bf2222>其他的 module</font>,或是<font color=#bf2222>外部電路</font>。 --- ## 定義 input/output port 1. 要讓 module 知道哪些是 input port 跟 output port。 ```clike= module vlike(in1, in2, Out); input in1, in2; output Out; . . . endmodule ``` --- ## 資料型態定義 1. 類似 c 語言,要先把所有的變數都先定義一遍。 ```clike= module vlike(in1, in2, Out); input in1, in2; output Out; reg in1, in2; wire Out; wire [3:0] temp, ... ; . . . endmodule ``` --- ## 電路描述 1. 將你的設計電路寫在這裡 ```clike= module vlike(in1, in2, Out); input in1, in2; output Out; reg in1, in2; wire Out, c; assign c = a & !b; assign Out = in1 & a & c; endmodule ``` # [:maple_leaf:Homepage:maple_leaf:](https://hackmd.io/s/ByZ-fyuHV)