'verilog'에 해당되는 글 4건
- 2009.05.31
- 2009.04.03
- 2009.04.03
- 2009.04.03
(예제)
module counter;
parameter Max = 0;
integer R;
initial
for (R=l; R <= Max; R = R
+ 1)
$display ("R= %d",
R)
endmodule
module main_module;
defparam COUNTER1.Max = 5,
COUNTER2.Max = 10;
counter COUNTER1 ();
counter COUNTER2 ();
endmodule
덧붙여 설명하면 parameter는 함수의 호출인자들의 꾸러미라고 볼 수 있습니다. defparam은 호출전에 그 꾸러미의 내용이 무엇인지 값들을 할당해 주는 것이고요.
즉, 마지막에 counter COUNTER1 (); 과 같이 호출을 하게 되면, counter모듈은 그 뒤의 COUNTER1라는 꾸러미를 풀어서 그 안의 parameter 값들을 조사합니다. COUNTER1에 Max라는 이름이 5라는 값으로 배정되어 있네요. 따라서 counter는 Max = 5로 초기화한 뒤 원래의 계수 알고리즘을 수행합니다.
cf) parameter와 defparam의 EBNF는 다음과 같습니다.
parameter_declaratLon ::=
parameter <range> <list_of_assignments>;
range ::= | [<expression>
: <expression>]
list_of_assignments ::=
<parameter_assignment>
|
<parameter_assignment> , <list_of_assignments>
parameter_assignment ::= <lvalue> = <expression>
module counter;
integer R;
initial
for (R=1; R <= 10; R = R + 1)
$display ("R= %d", R);
endmodule
dlsplay_statement ::= $display; I $display ( <arguments> );
write_statement ::= $write; I $write ( <arguments> );
arguments ::= <argument> | <argument>, <arguments>
argument ::= "<string>" I <expression>
\n New line Quotation
\t Tabulator
\\ Character\
\"
%% mark Character %
%h, %H Hexadecimal number
%d, %D Decimal number
%o, %O Octal number
%b, %B Binary number
%f, %F Real number
%c Single character
%s Character string
%t Time
%m Present module name
그럼 이제 Verilog 프로그램과 module에 대한 EBNF를 살펴보고 마치도록 한다.
VERILOG program ::= <module> I <VERILOG_program> <module>
module ::= module <name_of_module> <list of ports>;
<module item>
endmodule
name_of_module ::= <identifier>
list of ports ::= I ( <port_list> )
port_list ::= <identifier> I <port_list> , <port_list>
module_item ::= <parameter_declaration> I <input_declaration>
I <output declaration> | <inout declaration>
I <reg_declaration> I <integer_declaration> | <wire_declaration>
I <event_declaration> I <gate_instantiation>
I <module_instantiation> | <always_statement>
| <initial_statement> | <continuous_assign> I <function>
I <task> I <module_item> <module item>
module_instantiation ::= <type_of_module>
<name_of_instance> ( <module arguments> );
for_loop ::= FOR <variable>:=<number> TO <number> <stepsize> DO
<statement>;
Variable ::= <variable> <variable> I <digit> I a I b I c I d I e I f I g I h
I i I j I k | l I m I n I o I p I q I r I s I t I u I v I w I x
I y I z I A I B I C I D I E I F I G I H I I I J I K I L I M I N
I O I P I Q I R I S I T I U I V I W I X I Y I Z
stepsize ::= I STEP <number>