본문 바로가기

Verilog/HDLbits

[HDLBits] Alwaysblock2

1. 문제 및 설명

  • 다음 세 가지 방식으로 XOR 게이트를 구현하시오.
    1. assign 문 사용
    2. 조합논리 always 블록 사용 (always @(*))
    3. 클록 기반 always 블록 사용 (always @(posedge clk))
      • 이 경우는 플립플롭이 추가되므로 출력이 1클록 지연됨
      • 따라서 앞의 두 방식과 다른 회로가 만들어짐

2. 모듈 정의

module top_module(
    input clk,
    input a,
    input b,
    output wire out_assign,
    output reg out_always_comb,
    output reg out_always_ff   );

 

 

 

3. 답

module top_module(
    input clk,
    input a,
    input b,
    output wire out_assign,
    output reg out_always_comb,
    output reg out_always_ff   );
    
    assign out_assign = a^b;
    always@(*)
        begin
            out_always_comb = a^b;
        end
    
    always@(posedge clk)
        begin
            out_always_ff <= a^b;
        end
    

endmodule

'Verilog > HDLbits' 카테고리의 다른 글

[HDLBits] Always if2  (0) 2025.11.23
[HDLBits] Always if  (0) 2025.11.23
[HDLBits] Alwaysblock1  (0) 2025.11.18
[HDLBits] Module addsub  (0) 2025.11.18
[HDLBits] Module cseladd  (0) 2025.11.18