Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
xst.pdf
Скачиваний:
141
Добавлен:
11.06.2015
Размер:
5.64 Mб
Скачать

R

VHDL Combinatorial Circuits

architecture ARCHI of EXAMPLE is begin

process (A,B) variable X, Y : BIT;

begin

X := A and B;

Y := B and A; if X = Y then S <= '1' ;

end if; end process;

end ARCHI;

VHDL If...Else Statements

This section discusses VHDL if...else Statements, and includes:

“About VHDL If...Else Statements”

“VHDL If...Else Statements VHDL Coding Examples”

About VHDL If...Else Statements

If...else statements use true/false conditions to execute statements. If the expression evaluates to true, the first statement is executed. If the expression evaluates to false (or x or z), the Else statement is executed. A block of multiple statements may be executed using begin and end keywords. If... else statements may be nested.

VHDL If...Else Statements VHDL Coding Examples

This section gives the following If...Else Statement VHDL coding examples:

“If...Else Statement VHDL Coding Example”

If...Else Statement VHDL Coding Example

library IEEE;

use IEEE.std_logic_1164.all;

entity mux4 is port (

a, b, c, d : in std_logic_vector (7 downto 0); sel1, sel2 : in std_logic;

outmux : out std_logic_vector (7 downto 0)); end mux4;

architecture behavior of mux4 is begin

process (a, b, c, d, sel1, sel2) begin

if (sel1 = '1') then if (sel2 = '1') then

outmux <= a; else

outmux <= b; end if;

else

if (sel2 = '1') then

XST User Guide

www.xilinx.com

477

10.1

Chapter 6: XST VHDL Language Support

R

outmux <= c; else

outmux <= d; end if;

end if; end process;

end behavior;

VHDL Case Statements

This section discusses VHDL Case Statements, and includes:

“About VHDL Case Statements”

“Case Statements VHDL Coding Examples”

About VHDL Case Statements

Case statements perform a comparison to an expression to evaluate one of a number of parallel branches. The Case statement evaluates the branches in the order they are written. The first branch that evaluates to true is executed. If none of the branches match, the default branch is executed.

Case Statements VHDL Coding Examples

This section gives the following Case Statement VHDL coding examples:

“Case Statement VHDL Coding Example”

Case Statement VHDL Coding Example

library IEEE;

use IEEE.std_logic_1164.all;

entity mux4 is port (

a, b, c, d : in std_logic_vector (7 downto 0); sel : in std_logic_vector (1 downto 0); outmux : out std_logic_vector (7 downto 0));

end mux4;

architecture behavior of mux4 is begin

process (a, b, c, d, sel) begin

case sel is

when "00" => outmux <= a; when "01" => outmux <= b; when "10" => outmux <= c;

when others => outmux <= d; -- case statement must be complete end case;

end process; end behavior;

VHDL For...Loop Statements

This section discusses VHDL For...Loop Statements, and includes:

“About VHDL For...Loop Statements”

“For...Loop Statements VHDL Coding Examples”

478

www.xilinx.com

XST User Guide

 

 

10.1

R

VHDL Combinatorial Circuits

About VHDL For...Loop Statements

The for statement is supported for:

Constant bounds

Stop test condition using any of the following operators:

<

<=

>

>=

Next step computation falling within one of the following specifications:

var = var + step

var = var - step

(where var is the loop variable and step is a constant value)

Next and exit statements are supported

For...Loop Statements VHDL Coding Examples

This section gives the following For...Loop Statement VHDL coding example:

“For...Loop Statement VHDL Coding Example”

For...Loop Statement VHDL Coding Example

library IEEE;

use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all;

entity countzeros is port (

a : in std_logic_vector (7 downto 0);

Count : out std_logic_vector (2 downto 0) ); end mux4;

architecture behavior of mux4 is

signal Count_Aux: std_logic_vector (2 downto 0); begin

process (a) begin

Count_Aux <= "000"; for i in a'range loop

if (a[i] = '0') then

Count_Aux <= Count_Aux + 1; -- operator "+" defined -- in std_logic_unsigned

end if; end loop;

Count <= Count_Aux; end process;

end behavior;

XST User Guide

www.xilinx.com

479

10.1

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]