?? ch04.1.htm
字號:
</TABLE></P><P><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="2"><CAPTION ALIGN="TOP"><P CLASS="TableTitle"><A NAME="pgfId=8190"></A>Table 4-18: Reduction unarynand operator</CAPTION><TR><TH><P CLASS="CellHeading"><A NAME="pgfId=8200"></A>&</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8202"></A>0</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8204"></A>1</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8206"></A>x</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8208"></A>z</TH></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8210"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8212"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8214"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8216"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8218"></A>1</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8220"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8222"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8224"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8226"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8228"></A>x</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8230"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8232"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8234"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8236"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8238"></A>x</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8240"></A>z</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8242"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8244"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8246"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8248"></A>x</TD></TR></TABLE></P><P><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="2"><CAPTION ALIGN="TOP"><P CLASS="TableTitle"><A NAME="pgfId=8255"></A>Table 4-19: Reductionunary exclusive nor operator</CAPTION><TR><TH><P CLASS="CellHeading"><A NAME="pgfId=8265"></A>|</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8267"></A>0</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8269"></A>1</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8271"></A>x</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=8273"></A>z</TH></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8275"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8277"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8279"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8281"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8283"></A>x</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8285"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8287"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8289"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8291"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8293"></A>1</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8295"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8297"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8299"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8301"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8303"></A>x</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=8305"></A>z</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8307"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8309"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8311"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=8313"></A>x</TD></TR></TABLE></P><P><P CLASS="Body"><A NAME="pgfId=1077"></A><A HREF="#pgfId=632">Table 4-23</A>shows the results of applying reduction operators on different operands.</P><P><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="2"><CAPTION ALIGN="TOP"><P CLASS="TableTitle"><A NAME="pgfId=632"></A>Table 4-23: Results ofunary reduction operations</CAPTION><TR><TH><P CLASS="CellHeading"><A NAME="pgfId=701"></A>Operand</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=832"></A>&</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=1241"></A>~&</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=1242"></A>|</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=1243"></A>~|</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=1244"></A>^</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=1245"></A>~^</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=833"></A>comments</TH></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=834"></A>4'b0000</TD><TD><P CLASS="CellBody"><A NAME="pgfId=835"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1246"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1247"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1248"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1249"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1250"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=836"></A>No bits set</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=837"></A>4'b1111</TD><TD><P CLASS="CellBody"><A NAME="pgfId=866"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1251"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1252"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1253"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1254"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1255"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1261"></A>all bits set</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=889"></A>4'b0110</TD><TD><P CLASS="CellBody"><A NAME="pgfId=890"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1256"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1257"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1258"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1259"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1260"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=891"></A>even number of bits set</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=867"></A>4'b1000</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1262"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1263"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1264"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1265"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1266"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1267"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1268"></A>odd number of bits set</TD></TR></TABLE><P CLASS="SubSection"><A NAME="pgfId=638"></A>Shift operators</P><P><P CLASS="Body"><A NAME="pgfId=639"></A>The <I>shift operators</I> ,<< and >>, shall perform left and right shifts of their leftoperand by the number of bit positions given by the right operand. Bothshift operators shall fill the vacated bit positions with zeroes. If theright operand has an unknown or high impedance value then the result shallbe unknown. If the right operand is negative, the result shall remain thesame as the left operand--that is, the left operand shall not be shifted.</P><PRE><B>module</B> shift;<B>reg</B> [3:0] start, result;<B>initial begin</B> start = 1; result = (start << 2);<B>end</B><B>endmodule</B></PRE><P><P CLASS="Body"><A NAME="pgfId=642"></A>In this example, the register<CODE>result</CODE> is assigned the binary value <CODE>0100</CODE> , whichis <CODE>0001</CODE> shifted to the left two positions and zero filled.</P><P><P CLASS="SubSection"><A NAME="pgfId=644"></A>Conditional operator</P><P><P CLASS="Body"><A NAME="pgfId=645"></A>The <I>conditional operator</I>, also known as <I>ternary operator</I> , shall be right associative andshall be constructed using three operands separated by two operators inthe following format:</P><PRE>conditional_expression ::= expression1 <B>?</B> expression2 <B>:</B> expression3</PRE><P><P CLASS="BNFCapBody"><A NAME="pgfId=957"></A>Syntax 4-1: Syntaxfor conditional expression</P><P><P CLASS="Body"><A NAME="pgfId=647"></A>The evaluation of a conditionalexpression shall begin with the evaluation of expression1. If expression1evaluates to false (0), then expression3 shall be evaluated and used asthe result of the conditional expression. If expression1 evaluates to true(known value other than 0), then expression2 is evaluated and used as theresult. If expression1 evaluates to ambiguous value (<CODE> x</CODE> or<CODE>z</CODE> ), then both expression2 and expression3 shall be evaluatedand their results shall be combined, bit by bit, using <A HREF="#pgfId=1281">Table 4-24</A>to calculate the final result. If the lengths of the operands are different,the shorter operand shall be lengthened to match the longer and zero filledfrom the left (the high-order end).</P><P><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="2"><CAPTION ALIGN="TOP"><P CLASS="TableTitle"><A NAME="pgfId=1281"></A>Table 4-24: Ambiguouscondition results for conditional operator</CAPTION><TR><TH><P CLASS="CellHeading"><A NAME="pgfId=495"></A>?:</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=636"></A>0</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=637"></A>1</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=643"></A>x</TH><TH><P CLASS="CellHeading"><A NAME="pgfId=646"></A>z</TH></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=653"></A><B>0</B></TD><TD><P CLASS="CellBody"><A NAME="pgfId=664"></A>0</TD><TD><P CLASS="CellBody"><A NAME="pgfId=958"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=959"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=960"></A>x</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=665"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=666"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=961"></A>1</TD><TD><P CLASS="CellBody"><A NAME="pgfId=965"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=966"></A>x</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=667"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=827"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=967"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1073"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1074"></A>x</TD></TR><TR><TD><P CLASS="CellBody"><A NAME="pgfId=828"></A>z</TD><TD><P CLASS="CellBody"><A NAME="pgfId=829"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1075"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1269"></A>x</TD><TD><P CLASS="CellBody"><A NAME="pgfId=1270"></A>x</TD></TR></TABLE></P><P><P CLASS="Body"><A NAME="pgfId=830"></A>The following example of a tri-stateoutput bus illustrates a common use of the conditional operator.</P><PRE><B>wire</B> [15:0] busa = drive_busa ? data : 16'bz;</PRE><P><P CLASS="Body"><A NAME="pgfId=652"></A>The bus called <CODE>data</CODE>is driven onto <CODE>busa</CODE> when <CODE>drive_busa</CODE> is <CODE>1</CODE>. If <CODE>drive_busa</CODE> is unknown, then an unknown value is drivenonto <CODE>busa</CODE> . Otherwise, <CODE>busa</CODE> is not driven.</P><P><P CLASS="SubSection"><A NAME="pgfId=654"></A>Concatenations</P><P><P CLASS="Body"><A NAME="pgfId=655"></A>A concatenation is the joiningtogether of bits resulting from two or more expressions. The concatenationshall be expressed using the brace characters { and }, with commas separatingthe expressions within.</P><P><P CLASS="Body"><A NAME="pgfId=659"></A>Unsized constant numbers shallnot be allowed in concatenations. This is because the size of each operandin the concatenation is needed to calculate the complete size of the concatenation.</P><P><P CLASS="Body"><A NAME="pgfId=1271"></A>The next example concatenatesfour expressions:</P><PRE>{a, b[3:0], w, 3'b101}</PRE><P><P CLASS="Body"><A NAME="pgfId=657"></A>and it is equivalent to the followingexample:</P><PRE>{a, b[3], b[2], b[1], b[0], w, 1'b1, 1'b0, 1'b1}</PRE><P><P CLASS="Body"><A NAME="pgfId=660"></A>Concatenations can be expressedusing a repetition multiplier as shown in the next example.</P><PRE>{4{w}} // This is equivalent to {w, w, w, w}</PRE><P><P CLASS="Body"><A NAME="pgfId=662"></A>If a repetition multiplier isused on a function call operand, the function need not be evaluated multipletimes. For example,</P><PRE>result = {4{func(w)}}</PRE><P><P CLASS="Body"><A NAME="pgfId=1280"></A>may be computed as</P><PRE>result = {func(w), func(w), func(w), func(w)}</PRE><P><P CLASS="Body"><A NAME="pgfId=1287"></A>or</P><PRE>y = func(w) ;result = {y, y, y, y}</PRE><P><P CLASS="Body"><A NAME="pgfId=1279"></A>This is another form of expressionevaluation short-circuiting.</P><P><P CLASS="Body"><A NAME="pgfId=789"></A>The next example illustratesnested concatenations.</P><PRE>{b, {3{a, b}}} // This is equivalent to {b, a, b, a, b, a, b}</PRE><P><P CLASS="Body"><A NAME="pgfId=485"></A>The repetition multiplier mustbe a constant expression.</P><P><HR ALIGN=LEFT></P><P><A HREF="ch04.htm">Chapter start</A> <A HREF="ch04.htm">Previous page</A> <A HREF="ch04.2.htm">Next page</A></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -