# SPIM

## A MIPS R2000/R3000 Simulator

James Larus

Old Address | Current Address
Computer Sciences Department 1210 West Dayton Street University of Wisconsin Madison, WI 53706 larus@cs.wisc.edu | Microsoft Research One Microsoft Way Redmond, WA 98052 larus@microsoft.com

spim is a self-contained simulator for running MIPS R2000/R3000 assembly language programs. It reads and immediately executes assembly language code for this processor. spim provides a simple debugger and simple set of operating system services.

spim implements almost the entire MIPS assembler-extended instruction set for the R2000/R3000 (It omits some of the complex floating point comparisons and details of the memory system page tables.) The MIPS architecture has evolved considerably since then (in particular, from 32 to 64 bits), which means that spim will not run programs compiled for recent MIPS or SGI processors.

spim comes with complete source code and documentation. It also include a torture test to verify a port to a new machine.

spim implements both a simple, terminal-style interface and a visual windowing interface. On Unix, the spim program provides a terminal interface and the xspim program provides an X window interface. On PCs, the spim program provides a DOS interface or console interface and PCSpim provides a Windows interface..

## Downloading SPIM

Platform |  | Form | File
Unix or Linux system | spim xspim | Source code | http://www.cs.wisc.edu/~larus/SPIM/spim.tar.Z or http://www.cs.wisc.edu/~larus/SPIM/spim.tar.gz
Microsoft Windows (Windows 95, 98, NT, 2000) | spim PCSpim | Executable | http://www.cs.wisc.edu/~larus/SPIM/pcspim.exe
Source code | http://www.cs.wisc.edu/~larus/SPIM/pcspim_src.zip
Microsoft DOS | spim | Executable | http://www.cs.wisc.edu/~larus/SPIM/spimdos.exe

To run spim or xspim on a Unix or Linux system, copy either the compressed tar file (http://www.cs.wisc.edu/~larus/SPIM/spim.tar.Z) or the gzip'ed tar file (http://www.cs.wisc.edu/~larus/SPIM/spim.tar.gz). Both files contains source and must be compiled for a particular platform.

To run PCspim on a PC under Microsoft Windows, copy the file http://www.cs.wisc.edu/~larus/SPIM/pcspim.exe (Instructions: postscript.)

Source for the PC version (both PCspim and spim) is available separately in the file ftp://ftp.cs.wisc.edu/pub/spim/pcspim_src.zip

To run spim on a PC under MS/DOS, copy the file http://www.cs.wisc.edu/~larus/SPIM/spimdos.exe

There is no Macintosh version of spim (Yes, there should be).

## Documentation

Morgan Kaufmann has generously provided an on-line version of Appendix A from Hennessy & Patterson, Computer Organization and Design: The Hardware/Software Interface (as a Adobe PDF file). This is a more complete and up-to-date version of spim documentation included with spim.

The documentation included with spim is also online (as a postscript or Adobe PDF file). However Appendix A of Hennessy & Patterson, Computer Organization and Design: The Hardware/Software Interface, is a more complete and accurate description of the MIPS architecture and spim software.

There is some documentation for the Windows interface to spim: postscript or Adobe PDF file.

The reference manual for the MIPS architecture (including processors later than the R2000/R3000) is: Gerry Kane and Joe Heinrich, MIPS RISC Architecture, Prentice Hall, Englewood Cliffs, N.J. 07632 ISBN 0-13-1059254.

Another good book MIPS R2000 and R3000 programmers is: Erin Farquhar and Philip Bunce, The MIPS Programmer's Handbook, Morgan Kaufmann, San Francisco, CA, 1994, ISBN 1-55860-297-6.

However, the best book for MIPS programmers is: Dominic Sweetman, See MIPS Run, Morgan Kaufmann, San Francisco, CA, 1999, ISBN 1-55860-410-3.

## Latest Version

The current version of spim is 6.3, which contains the following changes from version 6.2:

- PCSpim interface simplified to 4 fixed panes, similar to xspim, which permit cut and paste.

- PCSpim console stays on the screen after assembly program terminates.

- Comments in assembly source displayed in text segment.

- NOP is standardized to sll $0 $0 0 (= 0x00000000)

- Fixed several bugs and missed optimization in computing immediate values in lw/sw instruction sequences.

- High 2 bits in negative branch offsets were incorrect.

- Display floating point registers with up to 18 digits of precision.

- New spim command (print_all_regs) prints all registers.

- Minor changes to compile spim under cygwin for Windows.

- Validate the range of immediate values in MIPS (but not pseudo) instructions.

- Fixed display of stack with non-word aligned $sp.

- New flags:

  - -delayed-branches Simulate MIPS delayed control transfers for branches, jumps, and calls

  - -delayed-loads Simulate MIPS non-interlocked loads.

## Copyright

spim is copyrighted by James Larus. The DOS and Windows ports were done by David A. Carley and are copyrighted by Morgan Kaufmann Publishers. spim can be freely used and distributed for non-commercial purposes (see the README file for details).

## SPIMSAL Note

spimsal is an old version of spim that ran on PCs running Windows 3.1 and Macintoshes. spimsal implements an extended version of the MIPS instruction set and is based on an old version of spim. It also does NOT run under Windows '95 or Windows NT. If you used this program on PCs and do not need the SAL instructions, you should get the new version.