The compiler which is written in Cosc 4P75 generates a set of pseudo instructions, or assembly instructions. These are high level "assembly" type instructions which dictate how a program will run and are an abstraction of a "more" real environment. Thus, the code generated must be translated to a platform which in turn implements the virtual machine. Only then will execution be possible.
The original version of the course back in the 1980s targeted the assembly pseudo instructions toward a stack architecture. This was run on a Vax 11-780 system. The compiler code that was generated, was linked with a set of Vax macros which provide the proper architecture. The resulting file was in effect Vax assembly instructions which then ran on the Vax architecture. These files where given the extension ".mar" which stood for macro. Since the 1980s the Vax has been retired and the departments computing power replaced by SGI servers. These servers were MIPS Risc based unlike the CISC based Vax. A problem with MIPS is that direct MIPS assembly files must deal with the multi-threading, multi-processing and timing idiosyncrasies which are inherent in the architecture. Since serious MIPS assembly is not required, a simplistic solution was to use a MIPS simulator.
The solution was SPIM, a fully functional R2000/R3000 MIPS simulator. MIPS assembly language code (MAL) would run under SPIM which provides a nice safe environment.
To get MAL code I took the existing Vax virtual machine, reverse
the macro instructions, and produced equivalent MAL code based on the
architecture. The program which takes the pseudo assembly instructions
and converts them to run under SPIM is called a translator. This
was named "marmalaid" to reflect the process of translating Vax .mar
to the current MAL code.
Marmalaid is written in 'C'. It accepts the compiler output (assembly pseudo instructions) files and produces 1 target MIPS assembly file. The input files are read using file I/O, however the output is simply streamed to the consol. The following syntax is used to translate the .spm files which the compiler generates to .mal files which SPIM can execute.
marmalaid <file1> <file2> etc > output.mal
Marmalaid was written in a standard ansi 'C', using no special functions. It has been compiled and run under UNIX on the departments SGIs, and under MSDOS. It has not been tested under linux, however, I don't see why it wouldn't work.
To compile for use on sandcastle. Down load the source code, "marmalaid.c".
cc marmalaid.c -o marmalaidThe MSDOS version was compiled using gcc under Cygwin. Compile using
gcc marmalaid.c -o marmalaidAlternately you may download the MSDOS executable. You will also need to download the cygwin1.dll file and place it in the same directory as the DOS version of marmalaid. The file you download is a self extracting zip file. Run cygwin.exe to extract cygwin1.dll.
The .mal code which marmalaid produces will execute directly under
SPIM. This has been tested using ver 6.5 on the SGIs, 6.0 MSDOS and 7.2
pcspim (Windows version). It is suggested you use the command line
since I/O can be redirected as needed. For example, here are some
on executing the Payroll.mal program produced above.
spim -file Payroll.mal
Input from the keyboard, output to the consol.
spim -file Payroll.mal < Payroll.dat
Input comes from the data file Payroll.dat, output is sent to the consol.
spim -file Payroll.mal < Payroll.dat > Myoutput.txt
Input comes from the data file Payroll.dat, output is sent to the file Myoutput.txt
Spim is available on sandcastle by typing "spim". Other platforms can be downloaded from the SPIM web site.
Since marmalaid only translates what it is given, then it is a slave to the garbage in garbage out syndrome. This means that it will produce valid MAL code which crashes quite nicely under SPIM if it was given buggy .spm files to work with.
If your code crashes (Normally Bad addresses under SPIM) then check to ensure you are generating the correct pseudo assembly instructions. The translator has been tested with Dave Hughes's compiler test files and produces working .mal files.
If you find a bug and can verify it as a bug then report it to me email@example.com
1. Marmalaid now generates
internal labels in the form _ML###.