VHDL Programming

(C. Jardin) #1

228 Chapter Eight


PORT( next_instr : IN BOOLEAN;
PORT( instr : OUT t_instr;
PORT( src : OUT INTEGER;
PORT( dst : OUT INTEGER);
END cpu_driver;

ARCHITECTURE a_cpu_driver OF cpu_driver IS
FILE instr_file : TEXT IS IN “instfile”;
BEGIN
read_instr : PROCESS( next_instr)
VARIABLE aline : LINE;
VARIABLE a_instr : STRING(1 to 4);
VARIABLE asrc, adst : INTEGER;
BEGIN
IF next_instr THEN
IF ENDFILE(instr_file) THEN
ASSERT FALSE
REPORT “end of instructions”
SEVERITY WARNING;
ELSE
READLINE( instr_file, aline);
READ( aline, a_instr);
READ( aline, asrc);
READ( aline, adst);
END IF;

instr <= convertstring(a_instr);
src <= asrc;
dst <= adst;

END IF;
END PROCESS read_instr;
END a_cpu_driver;

Package p_cpudefines type t_instr, the enumerated type that repre-
sents CPU instructions to be executed. The package also defines a function,
convert_string, that is used to convert the string value read in using
TextIO procedures into a t_instrtype. The conversion is necessary because
the TextIO package does not contain any procedures for reading in user-
defined types. (However, a designer can write a user-defined overloaded
procedure that has the same basic interface as the procedures in the
TextIO package.) This process is usually very straightforward, as seen by
the convert_stringprocedure.
Entity cpu_driveris the entity that reads in the file of instructions. It
has a single input port called next_instrwhich is used to signal the
entity to read in the next instruction. When a true event occurs on input
port next_instr, process read_instrexecutes. If the file is at the end
already, the ASSERTstatement is called, and a warning message is issued.
Free download pdf