[Tutor] Processor Simulator
Michael P. Reilly
arcege@speakeasy.net
Thu, 3 May 2001 07:59:50 -0400 (EDT)
Timothy M. Brauch wrote
> I have a project for my comp-sci class. I have to design a simulator
> for a processor, and I've decided to use Python. So, my question is,
> does anyone have any suggestions as to how to go about doing this?
> Also, I have to write simple files and load them into my simulator.
>
> My initial thoughts are to create a class with a bunch of function
> definitions for different processes. Such as add() and sub() and mul(),
> etc.
I would try to break different components into separate classes.
For example, a class for an ALU, another for external memory (maybe with
methods for "read" and "write", especially if you are simulating a RISC
type processor ;)), maybe one for a pipeline (later). Then you could have
the one "processor" class as the control mechanisms for the components.
But above all.. keep it simple. This seems oxymoronic, but as I suggest
above, instead of making some big list to simulate possibly megabytes of
RAM, just make read/write methods (there will be comparable load/store
commands anyway). Don't introduce a cache or special features at first;
as attractive as it might be to code, doing so might distract from the
"real" features.
> I also have to have a display window showing register enteries, which
> that I think I can do fairly easily. I was thinking of using the latest
> VPython which has a text function (I am doing this mostly because I have
> no experience with TK, otherwise I would use it, but right now I don't
> have the time to learn it).
At first, I would just concentrate on the class(es) for the processor
and worry about a user interface later. The project is not a graphical
program; keep display in mind while you are designing your program,
but keep the focus on the goal.
> As for the files, I would use something like readlines and string.split
> to break up my commands kept in the external file. I think I can handle
> that as well.
That sounds fine, especially at first. Also look at string.strip to
"nicely" get rid of the whitespace (including the line terminator).
Good luck! :)
-Arcege
--
+----------------------------------+-----------------------------------+
| Michael P. Reilly | arcege@speakeasy.net |