<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>my tech blog &#187; output reg</title>
	<atom:link href="http://billauer.se/blog/tag/output-reg/feed/" rel="self" type="application/rss+xml" />
	<link>https://billauer.se/blog</link>
	<description>Anything I found worthy to write down.</description>
	<lastBuildDate>Thu, 12 Mar 2026 11:36:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Verilog: Declaring each port (or argument) once</title>
		<link>https://billauer.se/blog/2009/07/verilog-standard-short-port-declaration-output-reg-autoarg/</link>
		<comments>https://billauer.se/blog/2009/07/verilog-standard-short-port-declaration-output-reg-autoarg/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 16:25:16 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[1364-2001]]></category>
		<category><![CDATA[output reg]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[standard]]></category>
		<category><![CDATA[Verilog]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=324</guid>
		<description><![CDATA[(&#8230;or why the Verilog-emacs AUTOARG is redundant) In Verilog, I never understood why port declarations appear both in the module declaration, and then immediately afterwards, along with the wires and registers. I mean, if the ports in the module declaration are always deducible from what follows immediately, why is the language forcing me to write [...]]]></description>
			<content:encoded><![CDATA[<p>(&#8230;or why the Verilog-emacs AUTOARG is redundant)</p>
<p>In Verilog, I never understood why port declarations appear both in the module declaration, and then immediately afterwards, along with the wires and registers. I mean, if the ports in the module declaration are always deducible from what follows immediately, why is the language forcing me to write it twice?</p>
<p>The short answer is: It doesn&#8217;t.</p>
<p>Let&#8217;s have a look on this simple module:</p>
<pre>module example(clk, outdata, inbit, outbit);
   parameter width = 16;

   input clk;
   input inbit;
   output outbit;
   output [(width-1):0] outdata;

   reg [(width-1):0]		outdata;

   assign 	outbit = !inbit;

   always @(posedge clk)
     outdata &lt;= outdata + 1;

endmodule</pre>
<p>There is nothing new here, even for the Verilog beginner: It demonstrates a simple combinatoric input-output relation. We also have an output, which happens to be a register as well (I didn&#8217;t even bother to reset it).</p>
<p>And as usual, every port is mentioned twice. Yuck.</p>
<p>Instead, we can go:</p>
<pre>module example #(parameter width = 16)
  (
   input clk,
   input inbit,
   output outbit,
   output reg [(width-1):0] outdata
   );	       

   assign 	outbit = !inbit;

   always @(posedge clk)
     outdata &lt;= outdata + 1;

endmodule</pre>
<p>At this point, I&#8217;d like to point out, that this is no dirty trick; This type of module declaration is explicitly defined in the Verilog 2001 standard (or by its official name, IEEE Std 1364-2001). This goes both for defining the ports and the parameters  (thanks to <a href="http://outputlogic.com/" target="_blank">Evgeni </a>for pointing out the possibility to set parameters as shown above).</p>
<p>According to the BNF definition in Annex A (A.1.3, to be precise), a module definition must take one of the two formats shown above, but mixing them is not allowed.</p>
<p>So here are few things to note when using the latter format:</p>
<ul>
<li>Each port declaration ends with a comma, not a semicolon. Same goes for parameter declarations.</li>
<li>It&#8217;s not allowed to declare anything about the port again in the module&#8217;s body. Repeating the port&#8217;s name as a wire or reg is not allowed.</li>
<li>Use &#8220;output reg&#8221; (which is legal in either format)  instead of declaring the register in the module&#8217;s body (which is not allowed in this setting)</li>
<li>Syntax highlighters and indenters may not work well</li>
</ul>
<p>The question is now: How could I not know about this?</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2009/07/verilog-standard-short-port-declaration-output-reg-autoarg/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
