`timescale 1ns/1ns module mux( input clk_a , input clk_b , input arstn , input brstn , input [3:0] data_in , input data_en , output reg [3:0] dataout ); //跨时钟,需要两级同步 reg en_temp; reg en_1,en_2; reg [3:0] data_temp; always @(posedge clk_a or negedge arstn) begin if(!arstn) begin data_temp <= 4'b0; end else if(data_en) begin data_temp <= data_in; end end always @(posedge clk_a or negedge arstn) begin if(!arstn) begin en_temp <= 1'b0; end else begin en_temp <= data_en; end end always @(posedge clk_b or negedge brstn) begin if(!brstn) begin en_1 <= 1'b0; end else begin en_1 <= en_temp; end end always @(posedge clk_b or negedge brstn) begin if(!brstn) begin en_2 <= 1'b0; end else begin en_2 <= en_1; end end always @(posedge clk_b or negedge brstn) begin if(!brstn) begin dataout <= 4'b0; end else if(en_2) begin dataout <= data_temp; end end endmodule