# 程式碼的執行順序
###### tags: `verilog` `digital design` `邏輯設計` `邏設`
[TOC]
## Get Started
剛接觸 verilog 時,很多人會有這個問題,程式不是一行一行的執行嗎?但是在硬體語言裡,這個是觀念<font color = #bf2222 size="6"> 並非永遠正確</font>。
- 正確:ex. testbench
- 錯誤:ex. 描述電路
## 重點 1
我們先來看個例子。
```clike=
module tk (a, b, c, out);
input a, b, c;
output out;
wire [3:0] a, b, c, out;
wire [3:0] op;
assign out = c or op; // 先接 out
assign op = a & b;
endmodule
```
```clike=
module tk (a, b, c, out);
input a, b, c;
output out;
wire [3:0] a, b, c, out;
wire [3:0] op;
assign op = a & b; // 先接 op
assign out = c or op;
endmodule
```
各位可以先試著把這兩個例子的電路圖畫出來。
## 重點 2
你會發現,兩個電路圖其實是完全一樣的,意思就是說,當你通電時,不管你哪一行 code 先寫,他通電的順序永遠是由左到右。

# [:maple_leaf:Homepage:maple_leaf:](https://hackmd.io/s/ByZ-fyuHV)