Testbench VHDL para una ALU: Simulación de Suma y Resta con Lectura y Escritura de Archivos

Informática y Telecomunicaciones2,89 KB

IEEE biblioteca;
-- La memoria es de tipo array (2 ** M-1 downto 0) de std_logic_vector (N-1 downto 0);
ieee.std_logic_1164.all uso;
-- MEM señal: memoria;
ieee.numeric_std.all uso;
std.textio.all uso;
ieee.std_logic_textio.all uso;
alu_tb entidad es
alu_tb fin;
SIM arquitectura de alu_tb es
-- tclk constante: el tiempo := 10ns;
Aluminio componente
-- clk_i <= no clk_i después de tclk / 2;
genéricos (
-- hacer clk asimétrico
clk_i <= '1' después de 25 ns cuando clk_i = '0' else '0' después de 75 ns;
N: positivo);
puerto (
a, b: in std_logic_vector (4*N-1 downto 0);
OPR: in std_logic;
ovfw_sign: out std_logic;
Resultado: out std_logic_vector (4*N-1 downto 0));
componente final;
N constante: positivo := 4;
a_i, b_i señal: std_logic_vector (4*N-1 downto 0);
opr_i señal: std_logic;
ovfw_sign_i señal: std_logic;
resultado_i señal: std_logic_vector (4*N-1 downto 0);
empezar
-- SIM
DUT: Aluminio
Mapa genérico (
N => N)
Mapa del puerto (
a => a_i,
b => b_i,
OPR => opr_i,
ovfw_sign => ovfw_sign_i,
Resultado => resultado_i);
-- Tecnología Electrónica. ITI-EI Feb Ext 2009
-- 10/10
proceso
arco de archivo: texto;
res: write_mode texto abierto es "resultado.txt";
buf, buf2: línea variable;
variable dat2: std_logic_vector (4*N-1 downto 0);
variable V1: std_logic;

empezar
file_open (arco, "datos.txt", read_mode);
opr_i <= '0';
mientras que no ENDFILE (arco) del bucle
readline (arco, buf);
hread (buf, dat2);
a_i <= dat2;
hwrite (buf2, dat2);
escribir (buf2, string'(" + "));
hread (buf, dat2);
b_i <= dat2;
hwrite (buf2, dat2);
escribir (buf2, string'(" = "));
esperar 10 ns;
V1 := ovfw_sign_i;
escribir (buf2, v1);
dat2 := resultado_i;
hwrite (buf2, dat2);
writeline (res, buf2);
end loop;
file_close (arco);
escribir (buf2, carácter'('\n'));
writeline (res, buf2);
file_open (arco, "datos.txt", read_mode);
opr_i <= '1';
mientras que no ENDFILE (arco) del bucle
readline (arco, buf);
hread (buf, dat2);
a_i <= dat2;
hwrite (buf2, dat2);
escribir (buf2, string'(" - "));
hread (buf, dat2);
b_i <= dat2;
hwrite (buf2, dat2);
escribir (buf2, string'(" = "));
esperar 10 ns;
V1 := ovfw_sign_i;
si v1 = '1' entonces
escribir (buf2, carácter'('-'));
otra cosa
escribir (buf2, carácter'(' '));
END IF;
dat2 := resultado_i;
hwrite (buf2, dat2);
writeline (res, buf2);
end loop;
file_close (arco);
file_close (res);
afirmar informe falso "simulación fin" severidad Error;
proceso de finalización;
SIM final;

Descargar

PDF Word HTML