fpga八选一多路选择器异或
时间: 2024-01-26 22:04:07 浏览: 28
以下是FPGA实现八选一多路选择器异或的代码和测试台代码:
```verilog
module mux8to1_xor(
input [7:0] data_in,
input [2:0] sel,
output reg out
);
always @(*) begin
case(sel)
3'b000: out = data_in[0];
3'b001: out = data_in[1];
3'b010: out = data_in[2];
3'b011: out = data_in[3];
3'b100: out = data_in[4];
3'b101: out = data_in[5];
3'b110: out = data_in[6];
3'b111: out = data_in[7];
endcase
end
always @(posedge clk) begin
if(reset) begin
out <= 1'b0;
end else begin
out <= out ^ data_in[sel];
end
end
endmodule
```
测试台代码:
```verilog
module mux8to1_xor_tb;
reg [7:0] data_in;
reg [2:0] sel;
wire out;
mux8to1_xor mux8to1_xor(
.data_in(data_in),
.sel(sel),
.out(out)
);
initial begin
data_in = 8'b00000000;
sel = 3'b000;
#10;
sel = 3'b001;
#10;
sel = 3'b010;
#10;
sel = 3'b011;
#10;
sel = 3'b100;
#10;
sel = 3'b101;
#10;
sel = 3'b110;
#10;
sel = 3'b111;
#10;
$stop;
end
endmodule
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)