The Computer Emulator
There are four major pieces of software involved: a C compiler,
an assembler, a linker, and the emulator or computer simulator
itself. Each are run independently by typing a command at
the unix shell prompt. Programs may be written in C, assembly
language, or a combination of the two: the C compiler produces
an assembly language file in exactly the form that a human
programmer would; the linker will link together multiple
files.
- Obtaining the software: Users of rabbit automatically
have access to the software if their PATH variable is set up
correctly. Make sure that /usr/local/simsys/ appears near the
beginning of your path. If you are not sure how to do that,
look here.
- The Compiler, command: cmp [options] filename
- Takes a single C source file and produces a single assembly language file
as output. Unlike the unix cc command, this compiles only, it does
not automatically assemble and link afterwards. If the filename has no dot in
it, the system assumes ".c"; the name of the assembly file produced is the
same is the C source file, but with the extension replaced by ".ass".
- Options are available for making the compiler produce all sorts of
debugging help. Look here for further information
on using the compiler effectively.
- From time to time, I have to make changes, correcting a mistake, or
adding a feature. Look here for a complete list
of all changes since the first release.
- The compiler is not likely to be quite perfect.
Tell me about problems.
It is quite possible I've made a few mistakes (deliberately of course),
or not realised that an unsupported feature might be very important
to you. Tell me, and I can adjust my priorities for making additions.
But remember, almost all problems can be avoided by putting inline
assembly code in your C programs.
- The compiler does not yet support all of ANSI/ISO C. Nearly all, but
not quite all. Look here for a list of what
is missing.
- The compiler adds some extensions to standard C, mainly to make it
more useful for operating systems programming and more helpful with
debugging. Look here for details.
- The standard libraries are extremely limited, this is because some
important exercises involve writing them yourself. Look
here for library information.
- Note: I was surprised to find that freeBSD already has a cmp command.
Either make sure that "." is at the beginning of your path rather than the
end, or use ./cmp to run the compiler instead, or rename the
compiler to something else.
- The Assembler, command: asm [options] filename
- Takes a single assembly source file and produces a single object file
as output. If the filename has no dot in
it, the system assumes ".ass"; the name of the object file produced is the
same is the assembly file, but with the extension replaced by ".obj".
- The compiler does not produce an object file, only an assebly file, so
the assembly stage is essentail after compilation.
- Options are available for making the assembler produce all sorts of
information about what it is doing. type asm -h for information.
- The assembler and the simulated computer share documentation.
Look here for html format, or
here for a word .doc.
- The Linker, command: lnk [options] filename [filename...]
- Takes any number of object files and produces a single executable file
as output. If the filename has no dot in
it, the system assumes ".obj"; the name of the executable file produced is the
same is the object file, but with the extension replaced by ".exe".
- The linker's job is not only to combine multiple files. The assembler
never produces a proper executable file; the linker is always needed.
- Options are available for making the linker produce all sorts of
information about what it is doing. type asm -h for information.
- Object files contain only printable ascii characters, so are human
readable, but until I produce documentation for the format, it will
probably require too much effort to understand what they say.
- The System, command: sys [options] [filename]
behaves like a normal computer with a very basic monitor (interactive
command line interpreter). If a filename is provided, it is expected to
be a proper executable file produced by the linker (extension ".exe" is
assumed if none is specified) and is loaded into memory ready for running.
If no file name is provided, you may use the load command at
the monitor prompt. The monitor prompts with ">", obeys the
command typed, and prompts again. The command to exit is "exit".
The system has a basic on-line help system that tells you all the
available commands, or gives details of an individual command. Type
"help" or "help command". Interactive
commands allow a user to sibgle step through or run a program, inspect
and modify memory and registers and the virtual memory system, and other
things.
Occasionally updates are made to the emulator, as students discover
the need or desire for something extra. the emulator command "version"
reports the current version number; the emulator also automatically
checks that it is the current version each time it is run.
For a description of updates, Look here.
Documentation is available in
html format and as a
word .doc file.
sys command options:
-
-r means automatically Run
the program after loading it, do not wait for a user command.
- -e means automatically Exit from the
system emulator after the program terminates.
- -q means be Quiet: do not
print any information while loading the program.
so, "sys -r -e -q file" is the way
to just run file.exe normally without any debugging or
user intervention.
- -o filename redirects Output to file.
so, "sys -r -e -q file -o outf" is the way
to just run file.exe with nothing appearing on the screen, but all
output going to the file outf instead.
- -v means automatically turn on Virtual
memory (or Paging) before loading the program. Normally paging
is turned off until the user or a running program turns it on.
- The exe command, automates the process of compiling,
assembling, linking, and running multi- and single- file programs.
- The exe command takes a number of file names as
parameters. If no extension is provided for a file, ".c" is assumed.
- All .c files are compiled and assembled.
- All .ass files are assembled.
- The resulting .obj files plus any given with the command
are linked into one executable.
- The emulator is started, running the .exe file. If an exe file is
specified in the command, it must be the only file.
- On termination, the emulator exits.
Example: "exe cat.c dog.ass" has the same effect
as cmp cat; asm cat; asm dog; lnk cat dog -o cat; sys;
load cat; run; exit.
- If there are any errors detected at any stage, the
procedure stops.
- Options modify the behaviour:
- "-is" prevents execution, the emulator is not run.
- "-ir" runs the emulator and loads the program, but does
not start execution.
- "-ie" converts into the -i option to cmp,
so that compilation errors to not stop the exe procedure.
- "-p" uses pico to edit the next-named file before
compiling or assembling it.
- "-v" is passed directly to the emulator, where
turns virtual memory (paging) on before loading the
program.
- "-q" prevents progress reports from being printed after each stage.
- "-o filename" is passed directly to the emulator,
where it makes all output from the running program be redirected
to the file, and not appear on the screen.
- "-d" deletes all generated files after use.