Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ЛО САПР / VHDL.PDF
Скачиваний:
43
Добавлен:
17.04.2013
Размер:
5.27 Mб
Скачать

VHDL Reference Guide

signal S4: SIGNED (3 downto 0); signal S8: SIGNED (7 downto 0);

Table 10-2 Number of Bits Returned by + and -

+ or -

U4

U8

S4

S8

 

 

 

 

 

U4

4

8

5

8

U8

8

8

9

9

S4

5

9

4

8

S8

8

9

8

8

In some circumstances, you might need to obtain a carry-out bit from the + or - operation. To do this, extend the larger operand by one bit. The high bit of the return value is the carry-out bit, as illustrated in the example below.

process

variable a, b, sum: UNSIGNED (7 downto 0); variable temp: UNSIGNED (8 downto 0); variable carry: BIT;

begin

temp := CONV_UNSIGNED(a,9) + b; sum := temp(7 downto 0);

carry := temp(8); end process;

Comparison Functions

The std_logic_arith package provides functions to compare UNSIGNED and SIGNED data types with each other and with the predefined type INTEGER. Foundation Express compares the numeric values of the arguments, returning a BOOLEAN value. For example, the following expression evaluates TRUE.

UNSIGNED’("001") > SIGNED’("111")

The std_logic_arith comparison functions are similar to the built-in VHDL comparison functions. The only difference is that the std_logic_arith functions accommodate signed numbers and varying bit-widths. The predefined VHDL comparison functions perform bit-wise comparisons and so do not have the correct semantics for comparing numeric values. (See the “Relational Operators” section of the “Expressions” chapter.)

10-10

Xilinx Development System

Foundation Express Packages

These functions produce comparators. The function declarations are listed in two groups, ordering functions (<, <=, >, and >=) and equality functions (= and /=) in the following examples.

Example 10-3: Ordering Functions

function "<"(L: UNSIGNED;

R: UNSIGNED) return Boolean;

function "<"(L: SIGNED;

R: SIGNED)

return Boolean;

function "<"(L: UNSIGNED;

R: SIGNED)

return Boolean;

function "<"(L: SIGNED;

R: UNSIGNED) return Boolean;

function "<"(L: UNSIGNED;

R: INTEGER)

return Boolean;

function "<"(L: INTEGER;

R: UNSIGNED) return Boolean;

function "<"(L: SIGNED;

R: INTEGER)

return Boolean;

function "<"(L: INTEGER;

R: SIGNED)

return Boolean;

function "<="(L: UNSIGNED;

R: UNSIGNED)

return Boolean;

function "<="(L: SIGNED;

R: SIGNED)

return Boolean;

function "<="(L: UNSIGNED;

R: SIGNED)

return Boolean;

function "<="(L: SIGNED;

R: UNSIGNED)

return Boolean;

function "<="(L: UNSIGNED;

R: INTEGER)

return Boolean;

function "<="(L: INTEGER;

R: UNSIGNED)

return Boolean;

function "<="(L: SIGNED;

R: INTEGER)

return Boolean;

function "<="(L: INTEGER;

R: SIGNED)

return Boolean;

function "" functions">">"(L: UNSIGNED; R: UNSIGNED) return Boolean;

function ">"(L: SIGNED;

R: SIGNED)

return Boolean;

function ">"(L: UNSIGNED;

R: SIGNED)

return Boolean;

function ">"(L: SIGNED;

R: UNSIGNED) return Boolean;

function ">"(L: UNSIGNED;

R: INTEGER)

return Boolean;

function ">"(L: INTEGER;

R: UNSIGNED) return Boolean;

function ">"(L: SIGNED;

R: INTEGER)

return Boolean;

function ">"(L: INTEGER;

R: SIGNED)

return Boolean;

function ="" functions">">="(L: UNSIGNED; R: UNSIGNED) return Boolean;

function ">="(L: SIGNED;

R: SIGNED)

return Boolean;

function ">="(L: UNSIGNED;

R: SIGNED)

return Boolean;

function ">="(L: SIGNED;

R: UNSIGNED)

return Boolean;

function ">="(L: UNSIGNED;

R: INTEGER)

return Boolean;

function ">="(L: INTEGER;

R: UNSIGNED)

return Boolean;

function ">="(L: SIGNED;

R: INTEGER)

return Boolean;

function ">="(L: INTEGER;

R: SIGNED)

return Boolean;

Example 10-4: Equality Functions

function "="(L: UNSIGNED;

R: UNSIGNED) return Boolean;

function

"="(L: SIGNED;

R: SIGNED)

return

Boolean;

function

"="(L: UNSIGNED;

R: SIGNED)

return

Boolean;

VHDL Reference Guide

10-11

Соседние файлы в папке ЛО САПР