2.1 Verilog Language - Basics

Kiwoong Nam·2025년 4월 11일

HDLBits

목록 보기
1/11

Updated at 25-04-11

Simple Wire

Wire

module top_module( input in, output out );
    assign out = in;
	
endmodule

assign 구문을 배우는 단순한 문제이다. 그냥 wiring 같지만 Verilog의 데이터 플로우는 단방향이라서, 우변의 신호가 좌변에 드라이브되므로 반대로 적어서는 안 된다.
C++의 참조자하고 비슷할지도?

Four wires

Wire4

module top_module( 
    input a, b, c,
    output w, x, y, z );
	assign w = a;
    assign x = b;
    assign y = b;
    assign z = c;
    
endmodule

하나의 input에 대해 두 개의 output을 assign할 수 있음을 보여주는 문제이다.

assign {w,x,y,z} = {a,b,b,c};

와 같이 한 번에 assign할 수도 있다.

Inverter

Notgate

module top_module( input in, output out );
	assign out = ~in;
	
endmodule

Negation의 사용법을 알려주는 문제이다.
C언어와 동일하게 Bitwise NOT은 ~를, Logical NOT은 !을 사용한다.

AND gate

Andgate

module top_module( 
    input a, 
    input b, 
    output out );
    assign out = a & b;

endmodule

C언어와 동일하게 Bitwise AND는 &, Logical AND는 &&를 사용한다.

NOR gate

Norgate

module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a|b);

endmodule

assign 구문에 조금 더 복잡한 구조를 넣어도 된다는 설명을 해 준다.

XNOR gate

Xnorgate

module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a^b);

endmodule

위 문제와 거의 동일하다.

Declaring wires

Wire decl
모범 답안

module top_module (
	input a,
	input b,
	input c,
	input d,
	output out,
	output out_n );
	
	wire w1, w2;		// Declare two wires (named w1 and w2)
	assign w1 = a&b;	// First AND gate
	assign w2 = c&d;	// Second AND gate
	assign out = w1|w2;	// OR gate: Feeds both 'out' and the NOT gate

	assign out_n = ~out;	// NOT gate
	
endmodule

내 답안

`default_nettype none
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   ); 
    assign out = (a&b)|(c&d);
    assign out_n = ~out;

endmodule

wire를 새로 선언해서 중간 과정을 계산할 수 있다는 걸 보여주는 문제인데, 나는 그냥 한 번에 처리했다.

7458 chip

7458

module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
    assign p1y = (p1a&p1b&p1c) | (p1d&p1e&p1f);
    assign p2y = (p2a&p2b) | (p2c&p2d);


endmodule

그림에 주어진 칩을 구현하면 되는 문제로, wire를 사용하기를 기대했을 것 같은데 귀찮아서 그냥 했다.

근데 왜 벨로그는 베릴로그 syntax highlighting 안해줌?????

0개의 댓글