Beginning FPGA Programming - Partie28
Beginning FPGA Programming - Partie28
Beginning FPGA Programming - Partie28
There are some VHDL-00 reserved words in the Table 7-1. Most of them are not recommended for use
as they are not supported by all tools.
■■Note The following web site descripts each reserved word in detail: http://www.xilinx.com/itp/
xilinx10/isehelp/ite_r_vhdl_reserved_words.htm.
7.1.3.1 Signal
Signals in VHDL are like a physical wire. They are used to connect different modules. Signals are declared as
shown in Listings 7-2 and 7-3.
Signals can be updated using a signal assignment statement. Figure 7-3 shows an example for the signal
data type.
128
Chapter 7 ■ Number Theory for FPGAs
In the signal_example, signals s_1, s_2, s_3, and s_4 are declared std_logic. All four of them get
assigned a value which is a logic operation result from lines 20 to 23. In line 24, the output S_out is assigned
the value of s_4.
There is always some delay in the signal assignments. This is different from the variable data type.
7.1.3.2 Variable
Variable data objects, like in C, are used to store local process/function information. They are used to hold
temporary data. Variables are declared with the statement shown in Listings 7-4 and 7-5.
129
Chapter 7 ■ Number Theory for FPGAs
In Figure 7-4, variables v_1, v_2, v_3, and v_4 are declared std_logic inside the v_p process. All four of
the variables are only allowed to be used within the process. All four of them get assigned a value which is
the logic operation result from lines 24 to 27. In line 29, the output S_out is assigned the value of v_4.
130
Chapter 7 ■ Number Theory for FPGAs
There are two differences between variables and signals. The first one is that variables are only able to
assign/update values within a process, procedure, or function. Signals can also be assigned a value by direct
assignment (as in Figure 7-3 lines 20-24).
The second example is where the value changes. We will use Listings 7-6 and 7-7 to show the difference.
begin
variable_1 := variable_2 ;
variable_2 := variable_1 + variable_3 ;
variable_3 := variable_2 ;
result <= signal_1 + signal_2 + signal 3;
end process;
end VAR
In Listing 7-8, the signals (signal_1, signal_2, signal_3) are computed at the same time that activate is
triggered. The signals will get updated as the following: signal_1 = 2, signal_2 = 1 + 3 = 4, signal_3 = 2, and
result = 1 + 2 + 3 = 6.
In Listing 7-9, the variables are computed at the time when activate is triggered in sequential order
(from top to bottom). The signals will get updated as the following: variable_1 = 2, variable_2 = 2 + 3 = 5,
variable_3 = 5, and result = 2 + 5 + 5 = 12.
■■Tip For the vast majority of the time use signals in your designs and don't mix signals and variables in the
same process
131
Chapter 7 ■ Number Theory for FPGAs
7.1.3.3 Constant
A constant is like variable data object, but the value of it cannot be changed. It can improve readability of the
VHDL code. A constant is declared as in Listing 7-8.
Constants can be declared at the beginning of architecture and can be used anywhere within the
architecture. If constants are declared within a process, then they can only be used inside the process.
7.1.4.1 Characters
A character is only ONE “character”; it is stored as its ASCII code. To use a character, you need to use single
quotation marks, as shown in Listing 7-10.
7.1.4.2 String
A string is a group of characters. You need to use double quotation marks when you want to use a string
(Listing 7-11).
7.1.4.3 Bit String
A bit string can treated as a mutation of a string. A string is used to represent characters and a bit string is
used to represent binary numbers or a sequence of bit values (Listings 7-12 through 7-14). Examples are
show as the following. All of them are showing value 90 and 240 but not the same number of bits for each
type: 90 in the binary bit string only uses 7 bit; Octal use 9 bit; and Hexagonal use 8 bit.
132