The WRint and WRch instructions provide a primitive form of output from the cpu. Semantically, WRint and WRch take a register as an argument and write the value of the register to output. WRint interprets the register as a signed integer and WRch interprets the register as the value of an ASCII character. The instruction format is 01001 xxx sss xxx ff where sss is the register of the data to be written and ff is 00 for WRint and 01 for WRch.
The IO is implemented by a VHDL module called io.vhdl. As you can see, the IO module takes as input the clock, the function field from the instruction, the 16-bit data to write and a WriteEnable (WR) control signal. On the falling edge of the clock, if the WriteEnable control signal is active (high) the IO module dumps the data to a file. You must change the path to the output file to point into your home directory before compiling this VHDL module. Also note that nothing is written to the file until the newline ('\n' = 10) is written. Until a newline is written, the data is cached into a variable. You could optionally modify this file to take the DUMP signal (the one sent to memory) and write the line into the file on that signal, because if the program ends without writing a newline, none of the output will appear in the output file. The module could also optionally take the RESET signal to clear the internal variable.
library ieee;
use ieee.std_logic_1164.all;
use ieee.math_real.all;
use ieee.numeric_std.all;
use std.textio.all;
entity io_unit is port (
func: in std_logic_vector(1 downto 0);
clk: in std_logic;
WR: in std_logic;
data_in: in std_logic_vector(15 downto 0)
);
end io_unit;
architecture io1 of io_unit is
begin
io_behavior:process(WR, clk)
file out_file : text is out "/u/l/e/lenz/private/552/programs/prog.out";
variable l: line;
variable data: integer;
begin
if (falling_edge(clk)) then
if WR = '1' then
data := to_integer(signed(data_in));
if func = "00" then
write(l, data);
elsif func = "01" then
if data = 10 then --newline
writeline(out_file, l);
else
write(l, character'val(data));
end if;
end if;
end if;
end if;
end process io_behavior;
end io1;