05.07.2013 Views

Xilinx Synthesis Technology User Guide

Xilinx Synthesis Technology User Guide

Xilinx Synthesis Technology User Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

XST <strong>User</strong> <strong>Guide</strong><br />

If...Else Statement<br />

If... else statements use true/false conditions to execute statements. If<br />

the expression evaluates to true, the first statement is executed. If the<br />

expression evaluates to false (or x or z), the else statement is executed.<br />

A block of multiple statements may be executed using begin and end<br />

keywords. If...else statements may be nested. The following example<br />

shows how a MUX can be described using an If...else statement.<br />

Example 7-2 MUX Description Using If... Else Statement<br />

module mux4 (sel, a, b, c, d, outmux);<br />

input [1:0] sel;<br />

input [1:0] a, b, c, d;<br />

output [1:0] outmux;<br />

reg [1:0] outmux;<br />

always @(sel or a or b or c or d)<br />

begin<br />

if (sel[1])<br />

if (sel[0])<br />

outmux = d;<br />

else<br />

outmux = c;<br />

else<br />

if (sel[0])<br />

outmux = b;<br />

else<br />

outmux = a;<br />

end<br />

endmodule<br />

Case Statement<br />

Case statements perform a comparison to an expression to evaluate<br />

one of a number of parallel branches. The Case statement evaluates<br />

the branches in the order they are written. The first branch that<br />

evaluates to true is executed. If none of the branches match, the<br />

default branch is executed.<br />

Note Do not use unsized integers in case statements. Always size<br />

integers to a specific number of bits, or results can be unpredictable.<br />

7-12 <strong>Xilinx</strong> Development System

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!