이 글에서는 Verilog 코드 작성 중 일반적으로 발생하는 "ERROR:HDLParsers:164 - "와 "ERROR:NgdBuild:924" 에러에 대해 알아보고, 이러한 에러를 해결하는 방법을 자세히 설명합니다.
문제상황
다음은 실무에서 사용될 수 있는 Verilog 코드의 일부입니다. 이 코드는 32비트 ALU를 구현한 것입니다.
module ALU_32bit(input [31:0] A, B, output [31:0] Y, input [2:0] ALU_Control);
wire [31:0] AND_out, OR_out, ADD_out, SUB_out, SLT_out;
wire [31:0] outputs [4:0];
and_32 a1(AND_out, A, B);
or_32 o1(OR_out, A, B);
add_32 add1(ADD_out, A, B);
sub_32 sub1(SUB_out, A, B);
slt_32 slt1(SLT_out, A, B);
assign outputs[0] = AND_out;
assign outputs[1] = OR_out;
assign outputs[2] = ADD_out;
assign outputs[3] = SUB_out;
assign outputs[4] = SLT_out;
assign Y = outputs[ALU_Control];
endmodule
이 코드에는 두 가지 문제가 있습니다. 코드를 컴파일하면 다음과 같은 에러 메시지가 표시됩니다.
에러로그 내용:
ERROR:HDLParsers:164 - "ALU_32bit.v" Line 18. Illegal left hand side of blocking assignment.
ERROR:NgdBuild:924 - "ALU_32bit.v" Line 18. Port 'ALU_Control' of instance 'Y' in module 'ALU_32bit' is not connected to any source signal.
원인분석
이 에러들은 코드에서 발생하는 두 가지 주요 문제로 인해 발생합니다.
- Blocking assignment에 잘못된 왼쪽 피연산자 사용: Verilog에서는 assign 키워드를 사용하여 wire에 값을 할당하고, = 키워드를 사용하여 reg 또는 integer에 값을 할당합니다. 여기서 발생하는 "ERROR:HDLParsers:164 - " 에러는 assign 키워드를 사용하여 reg에 값을 할당하려고 시도하면 발생합니다.
- 포트 연결이 누락: Verilog 모듈의 포트는 항상 올바르게 연결되어야 합니다. 포트가 올바르게 연결되지 않으면 "ERROR:NgdBuild:924" 에러가 발생합니다.
이 두 가지 문제를 해결하기 위해서는 코드를 살펴보고 수정해야 합니다.
해결방법-Blocking assignment 수정 및 포트 연결
에러가 수정된 코드와 수정된 부분에 대한 주석은 다음과 같습니다.
module ALU_32bit(input [31:0] A, B, output reg [31:0] Y, input [2:0] ALU_Control);
wire [31:0] AND_out, OR_out, ADD_out, SUB_out, SLT_out;
wire [31:0] outputs [4:0];
and_32 a1(AND_out, A, B);
or_32 o1(OR_out, A, B);
add_32 add1(ADD_out, A, B);
sub_32 sub1(SUB_out, A, B);
slt_32 slt1(SLT_out, A, B);
assign outputs[0] = AND_out;
assign outputs[1] = OR_out;
assign outputs[2] = ADD_out;
assign outputs[3] = SUB_out;
assign outputs[4] = SLT_out;
always @(*) begin // 수정: non-blocking assignment를 사용하도록 변경
case(ALU_Control)
3'b000: Y = outputs[0];
3'b001: Y = outputs[1];
3'b010: Y = outputs[2];
3'b011: Y = outputs[3];
3'b100: Y = outputs[4];
endcase
end
endmodule
해결된 코드의 작동 원리를 각 단계별로 설명하겠습니다.
- output 키워드 뒤에 reg 키워드를 추가하여 Y를 reg 타입으로 선언합니다. 이렇게 하면 blocking assignment를 사용할 수 있습니다.
- assign 키워드를 사용하는 대신, always @(*) 블록을 사용하여 Y의 값을 설정합니다. 이렇게 하면 blocking assignment를 사용할 수 있고, ALU_Control의 값이 변경될 때마다 Y의 값도 자동으로 업데이트됩니다.
이렇게 수정하면, 위에서 언급한 두 가지 에러가 해결됩니다.
참고링크
- Verilog HDL 관련 공식 문서: IEEE Standard for Verilog Hardware Description Language
- Xilinx ISE Design Suite 관련 문서: Xilinx ISE Design Suite User Guide
728x90