Hello world program#
To illustrate the general purpose of VHDL, the following block is a commented Hello world program which is saved in
a file named
-- Hello world program use std.textio.all; -- Imports the standard textio package. -- Defines a design entity, without any ports. entity hello_world is end hello_world; architecture behaviour of hello_world is begin process variable l : line; begin write (l, String'("Hello world!")); writeline (output, l); wait; end process; end behaviour;
.vhdextensions are used for VHDL source files, while
.vis used for Verilog.
.vhdis also interpreted as a Virtual Hard Disk file format, some users prefer
.vhdl, to avoid ambiguity. This is the case with GHDL’s codebase. However, in order to maintain backward-compatibility with legacy DOS systems, other users prefer
Unless you use especial characters, either UTF-8 or ISO-8859-1 encodings can be used. However, if you do, the latter should be used. The standard defines ASCII (7-bit encoding) or ISO Latin-1 (ISO-8859-1) as default. However, GHDL has a relaxing option,
--mb-comments(multi byte), to allow UTF-8 or other encodings in comments.
First, you have to compile the file; this is called analysis of a design file in VHDL terms. Run
ghdl -a hello.vhdlin the shell. This command creates or updates a file
work-obj93.cf, which describes the library
ghdl -e hello_worldin the shell. Command
-emeans elaborate, which is used to build a design, with the
hello_worldentity at the top of the hierarchy.
Last, you can directly launch the simulation running
ghdl -r hello_worldin the shell. The result of the simulation will be shown on screen:
If a GCC/LLVM variant of GHDL is used:
Analysis generates a file,
hello.o, which is the object file corresponding to your VHDL program. This is not created with mcode. These kind of object files can be compiled into foreign programs (see Linking GHDL object files to Ada/C).
The elaboration step is mandatory after running the analysis and prior to launching the simulation. This will generate an executable binary named
As a result,
-ris just a passthrough to the binary generated in the elaboration. Therefore, the executable can be run directly:
-rfor more informartion.