---
title: Hierarchical Design of 3-8 decoder
description: View the slide with "Slide Mode".
---
# Hierarchical Design of 3-8 decoder
>#### [Github](https://github.com/KAEDEKUKKI/decoder_3_8)
## 實驗內容
>* 使用 verilog 設計3對8解碼器
## 實驗過程
>使用兩個2對4解碼器來完成
>### 2 to 4 decoder
>```
>module decoder_2_4(E, In, Out);
> input E; //宣告 E 輸入
> input [1:0] In; //宣告 2-bit 輸入
> output [3:0] Out; //宣告 4-bit 輸出
> wire [3:0] Out; //宣告 4-bit wire訊號輸出
> assign Out = E ? 1'b1 << In : 4'h0; //E=1,Out往左移In個位元;E=0,Out=0
>endmodule
>```
>### 3 to 8 decoder
>
>```
>module decoder_3_8(E, In, Out);
> input E; //宣告 E 輸入
> input [2:0] In; //宣告 3-bit 輸入
> output [7:0] Out; //宣告 8-bit 輸出
> wire E1, G1, G2; //宣告 E1, G1, G2 wire訊號
> not u1(E1, In[2]); //not閘 u1 輸入:In[2] 輸出:E1
> and a1(G1, E, In[2]); //and閘 a1 輸入:E, In[2] 輸出:G1
> and a2(G2, E, E1); //and閘 a2 輸入:E, E1 輸出:G2
> decoder_2_4 block1(G1, In[1:0], Out[7:4]); //呼叫decoder_2_4 帶入 G1, In[1:0], Out[7:4]
> decoder_2_4 block2(G2, In[1:0], Out[3:0]); //呼叫decoder_2_4 帶入 G2, In[1:0], Out[3:0]
>endmodule
>```
## 實驗結果
>
## 心得
>對於這次的實驗中,讓我學習到如何使用兩個 2 to 4 decoder 來設計 3 to 8 decoder ,因為剛使用verilog對於語法還不是很熟悉,但語法還算簡單很好理解,把邏輯電路畫出來後更方便架構程式所需要的邏輯閘,就實驗結果下來並沒有什麼太大的問題。