HDLBits 포스팅은 Ligth Theme을 권장합니다.

(왼쪽 메뉴 하단)

 

문제는 반드시 HDLBits를 참고하세요! 보다 자세하게 적혀있습니다.

https://hdlbits.01xz.net/wiki/Mux2to1

 

Mux2to1 - HDLBits

 

hdlbits.01xz.net


Multiplexers

 

 


2-to-1 Multiplexer

 

Create a one-bit wide, 2-to-1 multiplexer. When sel=0, choose a. When sel=1, choose b.

sel = 0 이면 a를 선택하고, sel = 1 이면 b를 선택하는 1-bit 너비의 2 x 1 MUX를 만들어보세요.

Solution ↓

더보기
module top_module( 
    input a, b, sel,
    output out ); 
    
    assign out = (sel == 0)? a:b;

endmodule

 


2-to-1 Bus Multiplexer

 

Create a 100-bit wide, 2-to-1 multiplexer. When sel=0, choose a. When sel=1, choose b.

sel = 0 이면 a를 선택하고, sel = 1 이면 b를 선택하는 100-bit 너비의 2 x 1 MUX를 만들어보세요.

Solution ↓

더보기
module top_module( 
    input [99:0] a, b,
    input sel,
    output [99:0] out );

    assign out = (sel == 0)? a : b;
endmodule

 


9-to-1 Multiplexer

 

Create a 16-bit wide, 9-to-1 multiplexer. sel=0 chooses a, sel=1 chooses b, etc. For the unused cases (sel=9 to 15), set all output bits to '1'.

16-bit 너비의 9 x 1 MUX 를 만듭니다. sel=0은 a, sel=1은 b 등을 선택합니다. 사용하지 않는 경우(sel=9 ~ 15)는 모든 출력 비트를 '1'로 설정합니다.

Solution ↓

더보기
module top_module( 
    input [15:0] a, b, c, d, e, f, g, h, i,
    input [3:0] sel,
    output [15:0] out );

    assign out = (sel == 0)? a : (sel == 1)? b : (sel == 2)? c : (sel == 3)? d : (sel == 4) ? e : (sel == 5) ? f : (sel == 6) ? g : (sel == 7) ?  h : (sel == 8) ? i : 16'b1111_1111_1111_1111;
endmodule

 


256-to-1 Multiplexer

 

Create a 1-bit wide, 256-to-1 multiplexer. The 256 inputs are all packed into a single 256-bit input vector. sel=0 should select in[0], sel=1 selects bits in[1], sel=2 selects bits in[2], etc.

1-bit 너비의 256 x 1 MUX를 만듭니다. 256개의 입력은 모두 하나의 256-bit 입력 벡터로 채워집니다. sel=0은 [0]에서 선택하고, sel=1은 [1]에서 비트를 선택하고, sel=2는 [2]에서 비트를 선택해야 합니다.

Solution ↓

더보기
module top_module( 
    input [255:0] in,
    input [7:0] sel,
    output out );
    
    integer i;
    
    always @ (*) begin
        i = sel;
        out = in[i];
    end

endmodule

 


256-to-1 4-bit Multiplexer

 

Create a 4-bit wide, 256-to-1 multiplexer. The 256 4-bit inputs are all packed into a single 1024-bit input vector. sel=0 should select bits in[3:0], sel=1 selects bits in[7:4], sel=2 selects bits in[11:8], etc.

4-bit 너비의 256 x 1 MUX를 만듭니다. 256개의 4-bit 입력은 모두 하나의 1024-bit 입력 벡터로 채워집니다. sel=0은 [3:0]에서 비트를 선택하고, sel=1은 [7:4]에서 비트를 선택하고, sel=2는 [11:8]에서 비트를 선택해야 합니다.

Solution ↓

더보기
module top_module( 
    input [1023:0] in,
    input [7:0] sel,
    output [3:0] out );
    
    always @ (*) begin
        out = in[sel*4+3 -:4];
    end
endmodule

data[k*4 : k*5] 이런식으로는 compile이 안된다.

data [k*4 +:k]

왜 안될까