NAME
Hardware::Simulator::MIX - Knuth's famous virtual machine
SYNOPSIS
use Hardware::Simulator::MIX;
my $mix = new Hardware::Simulator::MIX;
while (!$mix->is_halted()) {
$mix->step();
}
DESCRIPTION
This implementation includes the GO button and the default loader is the answer to Exercise 1.3 #26.
Trace execution count and time for every instruction.
For detailed architecture information, search MIX in wikipedia.
CONSTRUCTOR
$mix = Hardware::Simulator::MIX->new(%options);
This method constructs a new Hardware::Simulator::MIX
object and returns it. Key/value pair arguments may be provided to set up the initial state. The following options correspond to attribute methods described below:
KEY DEFAULT
----------- --------------------
max_byte 64
timeunit 5 (microseconds)
MACHINE STATE
- Registers
-
Accessing registers:
$mix->{reg_name}
It is a reference to a MIX word. Available registers are listed below:
REGNAME FORMAT ----------- ----------------------- rA [?, ?, ?, ?, ?, ?] rX [?, ?, ?, ?, ?, ?] rI1 [?, 0, 0, 0, ?, ?] rI1 [?, 0, 0, 0, ?, ?] rI2 [?, 0, 0, 0, ?, ?] rI3 [?, 0, 0, 0, ?, ?] rI4 [?, 0, 0, 0, ?, ?] rI5 [?, 0, 0, 0, ?, ?] rI6 [?, 0, 0, 0, ?, ?] rI6 [?, 0, 0, 0, ?, ?] rJ [?, 0, 0, 0, ?, ?] pc Integer in 0..3999
Note: the names are case sensitive.
$mix->get_reg($reg_name); $mix->set_reg($reg_name, $wref);
- Memory
-
$mix->read_mem($loc); $mix->read_mem($loc, $l); $mix->read_mem($loc, $l, $r);
Return a MIX word from memory.
$loc
must be among 0 to 3999. If field spec$l
and$r
are missing, they are 0 and 5; If$r
is missing, it is same as$l
.$mix->read_mem(4);
equals to
$mix->read_mem(4,4);
Write memory.
$mix->write_mem($loc, $wref, $l, $r);
- Status
-
$mix->get_cmp_flag() returns an integer. If the returned value is negative, the flag is "L"; if the return value is positive, the flag is "G"; if the return value is 0, the flag is "E".
$mix->get_overflow() return 0 if there is no overflow. return 1 if overflow happen.
$mix->get_current_time() returns the current mix running time in time units since the last reset.
$mix->is_halted() returns 1 if the machine halts.
TRACING
- Get the execution count of an instruction
-
$mix->get_exec_count($loc);
- Get the time spent on an instruction
-
The result is in MIX time units.
$mix->get_exec_time($loc);
EXECUTION
IO DEVICES
General information about MIX io devices.
AUTHOR
Chaoji Li<lichaoji@gmail.com>
http://www.litchie.net
Please feel free to send a email to me if you have any question.
SEE ALSO
The package also includes a mixasm.pl which assembles MIXAL programs. Usage:
perl mixasm.pl <yourprogram>
This command will generate a .crd file which is a card deck to feed into the mixsim.pl. Typical usage:
perl mixsim.pl <yourprogram.crd>
Then type 'h' at the command line so you can see a list of commands. You can load a MIX program into the machine and see it run.