module name (input a, output b); ... endmodule | 기본 모듈 |
module name #(parameter N=8) (input [N-1:0] a); | 매개변수 모듈 |
input wire [7:0] data; | 8비트 입력 |
output reg [7:0] result; | 8비트 레지스터 출력 |
inout [7:0] bidir; | 양방향 포트 |
wire [7:0] w; | 와이어 (조합) |
reg [7:0] r; | 레지스터 |
integer i; | 정수 (32비트) |
parameter N = 8; | 컴파일 타임 상수 |
localparam M = N*2; | 로컬 파라미터 |
reg [7:0] mem [0:255]; | 256x8 메모리 배열 |
&, |, ^, ~ | 비트 AND, OR, XOR, NOT |
&&, ||, ! | 논리 AND, OR, NOT |
==, !=, ===, !== | 등호 (===는 x,z 포함) |
<, <=, >, >= | 비교 |
>>, <<, >>>, <<< | 시프트 (>>> 산술) |
? : | 삼항 조건 |
{a, b} | 연결 |
{4{a}} | 복제 (4개 복사) |
assign y = a & b; | 조합 로직 |
assign y = sel ? a : b; | 삼항 연산 mux |
assign #10 y = a; | 지연 포함 |
always @(posedge clk) | 상승 에지 트리거 |
always @(negedge clk) | 하강 에지 트리거 |
always @(posedge clk or negedge rst_n) | 비동기 리셋 |
always @(*) | 조합 (모든 입력) |
always_ff @(posedge clk) | SV: 순차 |
always_comb | SV: 조합 |
if (cond) ... else ... | If-else |
case (sel) 2'b00: ... default: ... endcase | Case 문 |
casez (sel) | z를 don't care로 case |
casex (sel) | x,z를 don't care로 case |
for (i=0; i<8; i=i+1) | For 루프 |
while (cond) ... | While 루프 |
generate for ... endgenerate | Generate 블록 |
always @(posedge clk) if (rst) q <= 0; else q <= d; | 동기 리셋 D 플립플롭 |
always @(posedge clk or negedge rst_n) if (!rst_n) q <= 0; else q <= d; | 비동기 리셋 D FF |
always @(posedge clk) if (en) q <= d; | 인에이블 D FF |
always @(posedge clk) cnt <= cnt + 1; | 카운터 |
assign mux_out = sel ? a : b; | 2:1 Mux |
assign dec = 1 << sel; | 디코더 |
dff u1 (.clk(clk), .d(d), .q(q)); | 이름 포트 연결 |
dff u1 (clk, d, q); | 위치 연결 |
dff #(.WIDTH(8)) u1 (...); | 파라미터 오버라이드 |
dff u1 (.clk, .d, .q); | SV: 암시적 포트 |
entity name is port (...); end name; | Entity 선언 |
architecture rtl of name is ... begin ... end rtl; | Architecture |
port (clk : in std_logic; q : out std_logic); | 포트 선언 |
generic (N : integer := 8); | 제네릭 파라미터 |
std_logic : ('0','1','X','Z',...) | 단일 비트 |
std_logic_vector(7 downto 0) | 8비트 벡터 |
unsigned(7 downto 0) | 부호 없는 산술 |
signed(7 downto 0) | 부호 있는 산술 |
integer range 0 to 255 | 범위가 있는 정수 |
type state_t is (IDLE, RUN, DONE); | 열거형 타입 |
constant N : integer := 8; | 상수 |
and, or, xor, not, nand, nor | 논리 연산자 |
=, /=, <, <=, >, >= | 비교 |
+, -, *, /, mod, rem | 산술 |
sll, srl, sla, sra, rol, ror | 시프트/회전 |
& | 연결 |
y <= a and b; | 신호 할당 |
y <= a when sel='1' else b; | 조건 할당 |
with sel select y <= a when "00", b when others; | 선택 할당 |
process (clk) begin if rising_edge(clk) then ... end if; end process; | 클럭 프로세스 |
process (all) begin ... end process; | 조합 (VHDL-2008) |
if rst = '1' then ... elsif rising_edge(clk) then ... | 비동기 리셋 |
if cond then ... elsif cond then ... else ... end if; | If 문 |
case sel is when "00" => ... when others => ... end case; | Case 문 |
for i in 0 to 7 loop ... end loop; | For 루프 |
while cond loop ... end loop; | While 루프 |
initial begin ... end | Initial 블록 |
#10; | 10 시간 단위 지연 |
@(posedge clk); | 클럭 에지 대기 |
always #5 clk = ~clk; | 클럭 생성기 |
$display("msg %d", var); | 메시지 출력 |
$monitor("a=%b b=%b", a, b); | 신호 모니터 |
$finish; | 시뮬레이션 종료 |
$dumpfile("wave.vcd"); $dumpvars; | 파형 덤프 |
clk <= not clk after 5 ns; | 클럭 생성기 |
wait for 10 ns; | 시간 대기 |
wait until rising_edge(clk); | 클럭 대기 |
report "message" severity note; | 메시지 출력 |
assert cond report "error" severity failure; | 단언 |