Design of A Microsoft Version of MIPS Microprocessor Simulator
Design of A Microsoft Version of MIPS Microprocessor Simulator
KEYWORDS
MIPS processors, Simulator, Assembly language, Instruction set, Assembler
ﺍﻟﺫﻱ ﻫﻭ ﻋﺒﺎﺭﺓ ﺒﺭﻨﺎﻤﺞ ﻤﺤﺎﻜﺎﺓ ﻟﻤﻌﺎﻟﺠﺎﺕMIPS-SIM ﻨﻘﻭﻡ ﻓﻲ ﻫﺫﺍ ﺍﻟﺒﺤﺙ ﺒﻭﺼﻑ ﺘﺼﻤﻴﻡ:ﺍﻟﻤﻠﺨﺹ
ﻭ ﻴﻌﻤل ﻀﻤﻥ ﺒﻴﺌـﺔ ﺭﺴـﻭﻤﻴﺔ ﻟﻠﺘﻔﺎﻋـل ﻤـﻊJava ﻤﻜﺘﻭﺏ ﺒﻠﻐﺔMIPS-SIM ﺍﻥ ﺒﺭﻨﺎﻤﺞ.MIPS
ﻋﺒﺎﺭﺓ ﻋﻥ ﻫﻴﻜﻠﻴﺔ ﺤﺎﺴﻭﺏ ﺸﺎﺌﻊ ﺍﻷﺴﺘﺨﺩﺍﻡ ﻓﻲ ﺍﻟﺼﻨﺎﻋﺔ ﻭ ﻫﻭ ﺍﻷﺴﺎﺱ ﻟﻠﻜﺘﺎﺏ ﺍﻟﺠﺎﻤﻌﻲMIPS . ﺍﻟﻤﺴﺘﺨﺩﻡ
ﻟﻠﻤﺅﻟﻔﻴﻥ ﺩﻴﻔﻴﺩ ﺒﺎﺘﺭﺴﻭﻥ ﻭ ﺠﻭﻥ ﻫﻴﻨﻴﺴﺴـﻲComputer Organization and Design ﺍﻟﻤﺸﻬﻭﺭ
ﺍﻥ ﺍﻟﻁﺒﻌﺔ ﺍﻟﺜﺎﻟﺜﺔ ﻤﻥ ﻫﺫﺍ ﺍﻟﻜﺘﺎﺏ ﻤﻥ ﺩﺍﺭ ﺍﻟﻨﺸﺭﻤﻭﺭﺠﺎﻥ. ﺠﺎﻤﻌﺔ400 ﺍﻟﻤﺴﺘﺨﺩﻡ ﻜﻜﺘﺎﺏ ﻤﻘﺭﺭ ﻓﻲ ﺃﻜﺜﺭ ﻤﻥ
ﻟﻘﺩ ﺘﻡ. ﻜﻬﻴﻜﻠﻴﺔ ﺭﺌﻴﺴﻴﺔ ﻟﻬﻴﻜﻠﻴﺔ ﻤﺠﻤﻭﻋﺔ ﺍﻟﺘﻌﻠﻴﻤﺎﺕMIPS32 ﻴﺴﺘﺨﺩﻡ ﺍﻟﻤﻌﺎﻟﺞ2005 ﻜﻭﻓﻤﺎﻥ ﻓﻲ ﺍﻟﻌﺎﻡ
ﻷﻏﺭﺍﺽ ﺘﻌﻠﻴﻤﻴﺔ ﺒﺨﺼﺎﺌﺹ ﻤﻔﻴﺩﺓ ﻟﻁﻼﺏ ﺍﻟﺒﻜﺎﻟﻭﺭﻴﻭﺱ ﻓﻲMIPS-SIM ﺘﺼﻤﻴﻡ ﺒﺭﻨﺎﻤﺞ ﺍﻟﻤﺤﺎﻜﺎﺓ
ﻋﻠﻭﻡ ﺍﻟﺤﺎﺴﻭﺏ ﺃﻭ ﻫﻨﺩﺴﺔ ﺍﻟﺤﺎﺴﻭﺏ ﻭ ﻤﺩﺭﺴﻴﻬﻡ ﻋﻠﻰ ﻭﺠﻪ ﺍﻟﺨﺼﻭﺹ ﺍﻟﺫﻴﻥ ﻴﺴﺘﺨﺩﻤﻭﻥ ﺍﻟﻜﺘﺎﺏ ﺃﻋﻼﻩ
Design of a Microsoft Version of MIPS Microprocessor Simulator
ﻓﻲ ﻤﺴﺎﻗﺎﺕ ﻤﺜـل ﻫﻴﻜﻠﻴـﺔ ﻭ ﻋﻤـﺎﺭﺓMIPS-SIM ﻴﻤﻜﻥ ﺍﺴﺘﺨﺩﺍﻡ ﺒﺭﻨﺎﻤﺞ .ﻜﻜﺘﺎﺏ ﺩﺭﺍﺴﻲ ﻤﻘﺭﺭ
ﻴﻘﻭﻡ ﺒﺭﻨـﺎﻤﺞ ﺍﻟﻤﺤﺎﻜـﺎﺓ.( compilers) ﻭ ﺘﺼﻤﻴﻡ ﺍﻟﻤﺘﺭﺠﻤﺎﺕ، ﺍﻟﺒﺭﻤﺠﺔ ﺒﻠﻐﺎﺕ ﺍﻟﺘﺠﻤﻴﻊ،ﺍﻟﺤﺎﺴﺒﺎﺕ
ﻜﻤﺎ ﻴﻘﻭﻡ ﺒﺭﻨﺎﻤﺞ ﺍﻟﻤﺤﺎﻜﺎﺓ. MIPS32 ﺒﻤﺤﺎﻜﺎﺓ ﻜل ﻤﺠﻤﻭﻋﺔ ﺍﻟﺘﻌﻠﻴﻤﺎﺕ ﺍﻟﺘﻭﺴﻌﻴﺔ ﻟﻤﻌﺎﻟﺞMIPS-SIM
ﺒﺘﻭﻓﻴﺭ ﺃﺩﺍﺓ ﺒﺴﻴﻁﺔ ﻟﺘﺼﺤﻴﺢ ﺃﺨﻁﺎﺀ ﺍﻟﺒﺭﻤﺠﺔ ﻜﻤﺎ ﻴﺤﺘﻭﻱ ﻋﻠﻰ ﻤﺠﻤﻭﻋـﺔ ﻤﺤـﺩﻭﺩﺓ ﻤـﻥMIPS-SIM
ﻭ ﺫﻟﻙ ﺒﺘﻨﻔﻴﺫ ﻋﺩﺓ ﺒﺭﺍﻤﺞMIPS-SIM ﻗﻤﻨﺎ ﺒﺎﺨﺘﺒﺎﺭ ﺒﺭﻨﺎﻤﺞ ﺍﻟﻤﺤﺎﻜﺎﺓ.ﺍﻟﺒﺭﺍﻤﺞ ﺍﻟﺨﺩﻤﺎﺘﻴﺔ ﻟﻨﻅﻡ ﺍﻟﺘﺸﻐﻴل
ﺩﻗﺔ ﻭ ﺼﺤﺔ ﻭ ﻓﻌﺎﻟﻴﺔ ﻭ ﻓﺎﺌﺩﺓ ﻟﻘﺩ ﺍﻅﻬﺭﺕ ﻨﺘﺎﺌﺞ ﻫﺫﻩ ﺍﻟﺘﺠﺎﺭﺏ .MIPS assembly ﻤﻜﺘﻭﺒﺔ ﺒﻠﻐﺔ
MIPS-SIM ﺒﺭﻨﺎﻤﺞ ﺍﻟﻤﺤﺎﻜﺎﺓ ﺘﺼﻤﻴﻡ
1. INTRODUCTION
The widely-used Computer Organization and Design [1] text, used at
over 400 universities [2] is based on the MIPS architecture and instruction
set. The third edition of this text uses standard 32-bit MIPS as the primary
teaching ISA. Since computer science and computer engineering
departments may not have adequate access to MIPS equipment to support
laboratory activities, software-based MIPS simulators may be used [2].
Additional reasons for using simulation software in an organization and
architecture course are described in [3], and two issues of the ACM Journal
of Educational Resources in Computing were devoted to computer
architecture simulators for educational purposes [4,5]. The SPIM [6]
simulator is used with Computer Organization and Design text and is
described in its Appendix [2].
MIPS is a simple, clean, and efficient RISC computer architecture [1].
The MIPS architecture has several variants that differ in various ways (e.g.,
the MIPS32 architecture supports 32-bit integers and addresses, and the
MIPS64 architecture supports 64-bit integers and addresses).
The architecture of the MIPS computers is simple and regular, which
makes it easy to learn and understand. The processor is a RISC processor
that contains 32 general-purpose 32-bit registers and a well-designed
instruction set that makes it a propitious target for generating code in a
compiler [6]. MIPS processor consists of an integer processing unit (the
CPU) and a collection of coprocessors. Figure 1 shows the general
architecture of the MIPS processor.
In this paper we design a MIPS simulator called MIPS-SIM. MIPS-SIM
is a simulator for the MIPS instruction set. It is a self-contained simulator
that runs MIPS32 assembly language programs. It reads and executes
assembly language programs written for this processor. MIPS-SIM also
provides a simple debugger and minimal set of operating system services.
The primary use of MIPS-SIM is educational. MIPS-SIM simulates
96
Mohammad A. Mikki, Mohammed R. El-Khoudary
MIPS32 because the third edition of the above mentioned text uses standard
32-bit MIPS as the primary teaching ISA.
97
Design of a Microsoft Version of MIPS Microprocessor Simulator
Obviously, there are already several very good simulators. The main
difference with our simulator is that it is being implemented in Java and is
intended for academic use.
Although running assembly programs on workstations that contain the
MIPS hardware is significantly faster, we use a simulator because these
workstations are not generally available. Another reason is that these
machines will not persist for many years because of the rapid progress
leading to new and faster computers. In addition, simulators can provide a
better environment for low-level programming than an actual machine
because they can detect more errors and provide more features than an
actual computer [6]. Finally, simulators are useful tools for studying
computers and the programs that run on them. Because they are
implemented in software, not silicon, they can be easily modified to add
new instructions, build new systems such as multiprocessors, or simply to
collect data [6].
The MIPS-SIM simulator implements the educationally important
portions of the MIPS instruction set utilized by third edition of the
Computer Organization and Design textbook [1]. Specifically, the MIPS-
SIM simulator implements complete MIPS instructions, complete
translation of MIPS instructions to MIPS machine language, advanced
exception handling for better and faster debugging, full size data and stack
segments, and support for most pseudo instructions. Pseudo-instructions are
expanded into one or more native MIPS instructions by the assembler.
The MIPS-SIM simulator is written in Java 1.4.2, and runs on IBM PCs
(or its compatibles) under Microsoft Windows environment.
The rest of the paper is organized as follows: Section 2 presents related
work. Section 3 presents the details of the implementation of MIPS-SIM.
Section 4 presents the pseudo code of MIPS-SIM. Section 5 validates the
design of the proposed simulator. Finally, section 6 concludes the paper.
2. RELATED WORK
A number of MIPS simulators have been developed over the years. Most
of these simulators can be classified by a small number of categories: those
designed for research use (e.g. MIPSI), those that focus on certain MIPS
architectural features such as pipelines (e.g. WebMIPS [8], SmallMIPS [9],
RTLSim[10]), those that depend on SPIM (e.g. MIPSASM, TinyMIPS), and
general purpose simulators [2]. Examples of the latter include MipsIt [11]
and SPIM [6]. Most MIPS simulators include features for visualizing and/or
animating MIPS components. SPIM is without doubt the most widely
98
Mohammad A. Mikki, Mohammed R. El-Khoudary
known and used MIPS simulator, serving both education and industry [2]. In
the following, we describe some of the existing MIPS simulators.
In [9] the authors create a simulator for the MIPS architecture. They call
their instruction set Small-MIPS, which is a subset of MIPS R2000
instruction set, plus some interesting instructions that they added. MIPS
assembler is created as part of the pipeline simulator project. It takes in a
human-readable assembly file and translates it into a data structure that is
only readable to the pipeline simulator. Not all of MIPS2000 instructions
are supported.
In [12] MIPS SDE (Software Development Environment) which is a
cross-development system for MIPS architecture processors is described. It
produces code for a variety of MIPS-based platforms and also simulator
platforms. It is intended for building and debugging statically-linked
applications to run in embedded environments on "bare-metal" CPUs or
light-weight operating systems.
In [13] MIPSI; MIPS simulator is developed. MIPSI is an instruction-
level simulator for the MIPS family of processors. Its main attributes are
simplicity and robustness. MIPSI runs on big or little Endian MIPS boxes
and on Alpha platforms.
In [6] SPIM MIPS simulator is described. SPIM is a self-contained
simulator that runs MIPS R2000/R3000 assembly language programs. It
reads and immediately executes assembly language code for this processor
(it does not execute binary programs). SPIM provides a simple debugger
and minimal set of operating system services. SPIM implements almost the
entire MIPS assembler-extended instruction set for the R2000/R3000.
SPIM implements both a simple, terminal-style interface and a window
interface.
Finally, in [2,14] MARS (MIPS Assembler and Runtime Simulator) is
described. MARS is a lightweight Interactive Development Environment
(IDE) for MIPS assembly language programming. It is intended for
educational-level use with Patterson and Hennessy's Computer Organization
and Design, third edition.
99
Design of a Microsoft Version of MIPS Microprocessor Simulator
the scalability in mind where the user can easily add new instructions. The
user can also reset the processor just by clicking one button. The simulator
can model parallel execution of multiple MIPS assembly programs on
multiple virtual MIPS processors. MIPS-SIM supports both single step and
normal execution. MIPS-SIM also automatically saves work done by the
user. MIPS-SIM includes a complete user manual.
The MIPS-SIM simulator implements the educationally important
portions of the MIPS instruction set utilized by Computer Organization and
Design, third Edition [1]. Specifically, the MIPS-SIM simulator
implements:
• Entire MIPS32 assembler-extended instruction set.
• Advanced exception handler for better and faster debugging.
• Full size data and stack Segments.
• Support for most pseudo instructions.
The MIPS-SIM program is divided into software modules. Each module
represents a component in the simulator. Modular design simplifies the
deign process, and makes it easy to enhance and debug the code.
100
Mohammad A. Mikki, Mohammed R. El-Khoudary
101
Design of a Microsoft Version of MIPS Microprocessor Simulator
Observable
-observers : ArrayList
MipsCPU
+notifyObservers()
-dataSegment : RandomAccessMemory +registerObserver(in observer : Observer)
-registerFile : RegisterFile +removeObserver(in observer : Observer)
-instructionFactory : InstructionsCacheProxy
-controlUnit : ControlUnit
-symbolTableManager : SymbolTableManager «interface»
-lexicalAnalyzer : LexicalAnalyzer Observer
-syntaxAnalyzer : SyntaxAnalyzer
+synchronizeState()
-sysCallIn : String
-sysCallOut : String
-RegisterController : RegisterController
+registerDataSegment(in dataSegment : RandomAccessMemory)
+registerControlUnit(in ControlUnit : ControlUnit)
+registerInstructionsFactory(in instructionsFactory : InstructionsCacheProxy) RegisterController
+registerRegisterFile(in registerFile : RegisterFile) -registerFields : Object []
+registerSymbolTableManager(in symbolTableManager : SymbolTableManager) +getRegisterValues() : String []
+registerLexicalAnalyzer(in lexicalAnalyzer : LexicalAnalyzer) +setRegisterValues() : String []
+registerSyntexAnalyzer(in syntaxAnalyzer : SyntaxAnalyzer)
+registerRegisterController(in graphical : Object) : RegisterController
+loadProgram(in path : String)
+compileProgram()
+getLexicalAnalysis() : StringBuffer
+getSyntaxAnalysis() : ArrayList
+getInstruction(in instruction : String) : InstructionNode
+getSymbolLocation(in label : InstructionNode) : InstructionNode
+getMemoryWord(in address : long) : MemoryWord
+getProgramCounter() : String
+getRegisterValue(in registerNumber : int) : String
+getMaxExecutionTime() : long
+getSyscallIn() : String
+getSyscallOut() : String
+getRegisterController() : RegisterController
+setRegisterValue(in registerNumber : int, in registerValue : String)
+setSymbol(in label : String, in location : InstructionNode)
+setMaxExecutionTime(in timeInMillis : long)
+setProgramCounter(in newLocation : InstructionNode)
+setSyscallOut(in sysout : String)
+setSyscallIn(in sysin : String)
+advanceProgramCounter()
+execute()
+executeSingle()
+resetCPU()
+synchronizeState()
+sysCall(in sysCallNo : int)
102
Mohammad A. Mikki, Mohammed R. El-Khoudary
103
Design of a Microsoft Version of MIPS Microprocessor Simulator
SymbolTableManager
-symbolTable : String [][]
+addSymbol(in label : String, in type : int, in location : long)
+getSymbol(in label : String) : long
SyntaxAnalyzer
-fromLexicalAnalyzer : StringBuffer
+setCodeFromLexicalAnalyzer(in code : StringBuffer)
-checkInstructionSyntax(in instruction : InstructionNode)
-addSymbol(in label : String, in location : InstructionNode)
FileLoader +analyzeCode() : ArrayList
-currentFile : File
+loadProgram(in String path)
+getCurrentFile() : StringBuffer
PseudoInstruction
-substituteInstructions : String
LexicalAnalyzer +convertToInstructions()
+setPreviousNode(in previousNode : InstructionNode)
-fileLoader : FileLoader
+getPreviousNode() : InstructionNode
-currentProgram : StringBuffer
+loadProgram(in path : String) : StringBuffer
-removeUnwantedCharacters()
+identifyToken(in token : String) : int
-isKeyWord(in token : String) : boolean
-isConstant(in token : String) : boolean
-isOther(in token : String) : boolean
-isRegister(in token : String) : boolean
+analyzeProgram() : StringBuffer
104
Mohammad A. Mikki, Mohammed R. El-Khoudary
105
Design of a Microsoft Version of MIPS Microprocessor Simulator
InstructionsCacheProxy
-Cache : Hashmap -$ingleInstance 1
-instructionFactory : InstructionsFactory
+getInstruction(in Instruction : String) : MIPSInstruction
+clearCache() InstructionsFactory 1
-InstructionsFactory : InstructionsFactory
1 +getInstructionFactory() : InstructionsFactory
*
+getInstruction(in Instruction : String) : MIPSInstruction
«instance»
<<throws>>
«exception»
«interface» InstructionNotFoundException
MIPSInstruction
+checkSyntax() : String
+execute()
+getAssimblyBitString() : String Syscall
+getInstructionType() : int -assembly : String
-parameters : ArrayList
+checkSyntax() : String
+execute()
+getAssemblyBitString() : String
+getInstructionType() : int
106
Mohammad A. Mikki, Mohammed R. El-Khoudary
«interface» Observable
Observer -observers : ArrayList
+synchronizeState()
+notifyObservers()
+registerObserver(in observer : MemoryObserver)
+removeObserver(in observer : MemoryObserver)
RegisterFile
-registers : Hashmap
-systemRegisters : Hashmap
-registersBaseAddress : long
-systemRegistersBaseAddress : long
+getRegisterValue(in registerNumber : int) : String
+getSystemRegisterValue(in registerNumber : int) : String
+setRegisterRegisterValue(in registerNumber : int, in registerValue : String) RandomAccessMemory
+setSystemRegisterValue(in registerNumber : int, in registerValue : String) -rootWord : MemoryWord
+isSystemRegister(in registerNumber : int) : boolean
+isRegister(in registerNumber : int) : boolean +getMemoryWord(in address : long) : MemoryWord
<<throws>>
+clearRegisters() +resetRAM()
+getRegisterBaseAddress(in registerNumber : int) : long
+getSystemRegisterBaseAddress(in registerNumber : int) : long *
1
«exception»
<<throws>> MemoryOutOfBoundException
MemoryWord
-leftChild : MemoryWord
-rightChil : MemoryWord
«exception» -address : long
RegisterNotFoundException <<throws>> -word : String []
+insertOrGet(in requestedLocation : long) : MemoryWord
+setRightWord(in rightChild : MemoryWord)
+setLeftWord(in leftChild : MemoryWord)
«exception»
+setByte(in byteNo : int, in value : String)
InvalidDataException +setAddress(in address : long)
+getByte() : String
+getAddress() : long
+getRightWord() : MemoryWord
+getLeftWord() : MemoryWord
107
Design of a Microsoft Version of MIPS Microprocessor Simulator
can update the content of text segment pane automatically when any change
in the text segment occurs.
O bs erv able
-observe rs : A rra yL ist
+ notifyO bserve rs()
+ re giste rO bse rver(in observe r : O bserve r)
+ re m oveO b se rver(in observe r : O bserve r)
ControlU nit
-te xtS eg m ent : A rrayList
-instructionP o inter : InstructionN od e
-m axE xecutio nTim e : lo ng
+ getR ootInstru ction () : InstructionN od e
+ getC urren tIn structio n() : Instru ction No de
+ getM axE xe cu tionTim e() : long
+ setM a xE xecutionT im e (in tim e InM illis : lo ng )
+ setTe xtS eg m ent(in textS egm e nt : A rra yL ist)
+ advanceInstru ctio nP ointe r()
+ exe cu te ()
+ exe cu te S ingle ()
+ clea rTe xtS eg m en t()
InstructionN ode
-instru ction : S trin g
-pa ra m eters : String []
+ ge tIn structio nType () : int
+ ge tA sse m blyB itString () : String
+ ge tIn structio n() : S trin g []
+ checkS yntax() : S tring
+ execute ()
108
Mohammad A. Mikki, Mohammed R. El-Khoudary
109
Design of a Microsoft Version of MIPS Microprocessor Simulator
110
Mohammad A. Mikki, Mohammed R. El-Khoudary
111
Design of a Microsoft Version of MIPS Microprocessor Simulator
112
Mohammad A. Mikki, Mohammed R. El-Khoudary
113
Design of a Microsoft Version of MIPS Microprocessor Simulator
114
Mohammad A. Mikki, Mohammed R. El-Khoudary
loaded into the corresponding windows (panes) in the GUI. The file is
loaded into the editor window.
115
Design of a Microsoft Version of MIPS Microprocessor Simulator
separately here for the purposes of the simulator. There are 32 general
registers in the MIPS CPU. Register file window shows all these 32
registers using a top-down scroll list. In the register file window each
register's value at the last cycle is displayed in hexadecimal format (default)
or decimal format. The register value format is selected using the two radio
buttons (hexadecimal and decimal) at the bottom of the register file window.
Only one button may be selected at any time. Similar to memory, register
values are editable. If the user tries to edit a register and he/she enters an
illegal value, the simulator will not accept it and will display an error
message in the simulator status pane.
There is a checkbox in front of each register in the register file window.
This checkbox is used to select/unselect the register. Selected registers can
be colored with a specified color when clicking the mouse on the "color
selected registers" button at the bottom of the register file window. The user
can also detach the selected registers by clicking the mouse on the "detach
selected registers" button. This button is also at the bottom of the register
file window. When the user detaches the selected registers, they are
displayed in a new floating and resizable window that can be put anywhere
on the computer screen that is suitable to the user. This enables the user to
focus on specific registers that he/she selects.
4. MIPS-SIM CODE
In Figure 15 we show a high level pseudo code of MIPS-SIM.
Method main creates an instance of MIPS-SIM and passes the MIPS
assembly file to it. Then, it calls executeFile method. Method MipsSim
loads the MIPS assembly file to be simulated. Method lexicalAnalysis
converts the file into a stream of bytes, analyzes the code, checks for
keywords, registers, and other words, and converts the stream into an XML
file. The lexicalAnalysis method also builds a symbol table with unresolved
references. The XML file is passed to syntaxAnalysis method.
syntaxAnalysis method resolves the unresolved references in the symbol
table and transforms the XML file into a tree of instruction objects
(InstructionNodes). Method executeFile runs the code either in a single step
mode or in normal mode. Method executeFile calls method
executeInstruction which runs a single instruction whose address is passed
to it by executeFile method. The main method and the MipsSim method are
part of the CPU module, the lexicalAnalysis method and syntaxAnalysis
method are part of the lexical and syntax analysis module, the executeFile
method and executeInstruction method are part of the control module.
116
Mohammad A. Mikki, Mohammed R. El-Khoudary
5. SIMULATION
In this section we validate and verify the correctness of the design of
MIPS-SIM by presenting some experimental results. The experiments range
from simple to complex and cover various aspects of the simulator. We
design several MIPS programs to test its various features and capabilities.
117
Design of a Microsoft Version of MIPS Microprocessor Simulator
These programs use most of the features and instructions of the MIPS
assembly language. The results show that our design is correct, robust,
reliable and accurate. These test programs are presented in the following
examples.
When the above code is compiled using MIPS-SIM, the data in the text
window is as follows:
[0x00400024] addi $s0,$zero,1 0x20100001 I
[0x00400028] addi $s1,$zero,2 0x20110002 I
[0x0040002c] add $s2,$s0,$s1 0x02119020 R
[0x00400030] jr $ra 0x03e00008 R
As expected, results are correct, setting $s0 to 1, $s1 to 2, and $s2 the
summation of $s0 and $s1 which is equal to 3.
118
Mohammad A. Mikki, Mohammed R. El-Khoudary
When the above code is compiled using MIPS-SIM, the data in the text
window is as follows:
Figure 19: Partial view of the register pane for example 5.2
119
Design of a Microsoft Version of MIPS Microprocessor Simulator
After the execution of the above code using MIPS-SIM, $s0 to $s4
register values are set to those shown in the register pane in Figure 21.
These registers contain the correct and expected values.
Figure 21: Partial view of the register pane for example 5.3
Enter an integer:
7
The factorial is:
5040
Several runs of the above code were made with different inputs and the
results were correct.
120
Mohammad A. Mikki, Mohammed R. El-Khoudary
.text syscall
.globl main add $a0,$zero,$v1
main: addi $v0,$zero,1
addi $sp,$sp,-4 syscall
sw $ra,0($sp) lw $ra,0($sp)
la $a0,string0 jr $ra
addi $v0,$zero,4 factorial:
syscall add $s0,$a0,$zero
addi $v0,$zero,5 addi $v1,$zero,1
syscall loop:
add $a0,$v0,$zero mul $v1,$s0,$v1
add $s7,$v0,$zero addi $s0,$s0,-1
sw $ra,0($sp) bne $s0,$zero,loop
add $a0,$s7,$zero jr $ra
jal factorial .data
lw $ra,0($sp) space:
la $a0,string2 .word 10
addi $v0,$zero,4 string0: .asciiz "Enter an integer:\n"
string1: .asciiz "The factorial is: \n"
Figure 23 shows the MIPS assembly code for the summation program.
The above program was executed using MIPS-SIM and below is the
result.
Enter an integer:
10
The summation is:
55
Several runs of the above code were made with different inputs and the
results were correct.
121
Design of a Microsoft Version of MIPS Microprocessor Simulator
2 3 5 7 11 13 17 19 23 29
122
Mohammad A. Mikki, Mohammed R. El-Khoudary
Figure 24: MIPS assembly code for the bubble sort algorithm.
123
Design of a Microsoft Version of MIPS Microprocessor Simulator
Figure 25: MIPS assembly code for matrix multiplication of 2x2 matrices
6. CONCLUSION
In this paper we describe the implementation of MIPS-SIM (MIPS
Simulator). MIPS-SIM is a GUI, Java-based simulator for the MIPS
assembly language. The MIPS-SIM simulator has been implemented with
characteristics that are especially useful to undergraduate computer science
and engineering students and their instructors. MIPS-SIM also provides a
124
Mohammad A. Mikki, Mohammed R. El-Khoudary
ACKNOWLEDGEMENT
The authors would like to thank the Islamic University of Gaza, Gaza,
Palestine, for partial financial support of this research.
REFERENCES
[1] Patterson D, Hennessy J., Computer Organization and Design: The
Hardware/Software Interface. 3rd edition, Morgan Kaufmann, San
Francisco, CA, 2005.
[2] Vollmar K., Sanderson P., MARS: An Education- Oriented MIPS
Assembly Language Simulator, SIGCSE' 06, ACM, Mar. 1- 5, 2006,
Houston, Texas, USA.
[3] Wolffe, G., Yurcik, W., Osborne, H., Holliday, M., Teaching Computer
Organization/Architecture With Limited Resources Using Simulators,
ACM SIGCSE Bulletin 34, (1), 2002, p 176 – 180.
[4] Yurcik, W. (guest editor), ACM Journal on Educational Resources in
Computing, Vol. 1, No. 4, Dec. 2001.
[5] Yurcik, W. (guest editor), ACM Journal on Educational Resources in
Computing, Vol. 2, No. 1, Mar. 2002.
[6] Larus J., SPIM: A MIPS32 simulator:
http://www.cs.wisc.edu/~larus/spim.html
[7] Karamcheti V., Nachos Project Guide, Spring 2000, Department of
Computer Science, Courant Institute of Mathematical Sciences, New
York University, New York, USA.
[8] Branovic, I., Giorgi, R., Martinelli, E., WebMIPS: A New Web-Based
MIPS Simulation Environment for Computer Architecture Education,
125
Design of a Microsoft Version of MIPS Microprocessor Simulator
126