VHDL Programming

(C. Jardin) #1

Advanced Topics 227


The last entry in the input file shows a line with two input values on
the line. When the line is read into the my_linevariable, both values
exist in the line, but because there is only one READprocedure call, only
the first value is read from the line.
More than one data item can be read from a single line, as well as data
items of any types. For instance, a TextIO file could be a list of instructions
for a microprocessor. The input file could contain the type of instruction, a
source address, and a destination address. This is shown by the following
simple example:

USE WORK.TEXTIO.ALL;

PACKAGE p_cpu IS
TYPE t_instr IS (jump, load,
TYPE t_instr IS (store, addd,
TYPE t_instr IS (subb, test, noop);

FUNCTION convertstring( s : STRING) RETURN t_instr;

END p_cpu;

PACKAGE BODY p_cpu IS
FUNCTION convertstring( s : STRING) RETURN t_instr IS
SUBTYPE twochar IS string(1 to 2);
VARIABLE val : twochar;
BEGIN
val := s(1 to 2);
CASE val IS

WHEN “ju” =>
RETURN jump;
WHEN “lo” =>
RETURN load;
WHEN “st” =>
RETURN store;
WHEN “ad” =>
RETURN addd;
WHEN “su” =>
RETURN subb;
WHEN “te” =>
RETURN test;
WHEN “no” =>
RETURN noop;
WHEN others =>
RETURN noop;
END CASE;
END convertstring;
END p_cpu;

USE WORK.p_cpu.ALL;
USE WORK.TEXTIO.ALL;
ENTITY cpu_driver IS
Free download pdf