You are on page 1of 13

Spring

Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Statement Purpose:
The purpose of this Lab is to familiarize students with the assembly programming
environment they will be going to use throughout this course. This Lab introduces the
basics of SPIM Simulator and demonstrates how this simulator software facilitates the
process of programming.

Activity Outcomes:
The students will know how to download, install and use SPIM simulator and text
editing programs. Further they will be aware of how these software facilitate the
process of programming.

Instructor Note:
Read the exercises below and submit your answer in the answer sheet available at
the end. English will be the official language throughout the discussion.

Names

1. ....

CPCS-214 - The Lab Note

I.D

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Introduction to Assembly Language


What is Assembly language ?

Assembly language is the symbolic representation of a computers binary


encoding machine language.

Machine language is a binary representation used for communication within


a computer system.

Assembly language is more readable than machine language because it uses


symbols instead of bits.

How does it work?

A tool called an Assembler translates assembly language into binary


instructions.

An assembler reads a single assembly language source file and produces


an object file containing machine instructions and bookkeeping information
that helps combine several object files into a program.

Another tool, called a Linker combines a collection of object and library files
into an executable file which a computer can run.

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Why we study Assembly ?

Assembly language is still important to write programs in which speed or size


are critical or to exploit hardware features that have no analogues in high-level
languages.

We will study MIPS Assembly language, assembly programming on MIPS


machine.

MIPS (Microprocessor without Interlocked Pipeline Stages) is a


microprocessor architecture developed by MIPS Technologies.

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

What is SPIM ?

SPIM is a software simulator that runs assembly language programs written


for MIPS processors.
SPIMs name is just MIPS spelled backwards.
SPIM is a simple, easy-to-use program, can read and immediately execute
assembly language files.

Download and Install SPIM

1- Go to the website

http://www.hashimi.ws/cs214/spimstepguide.php

2- Download the program SPIM as shown in Figure(1)

Figure (1)
3- Unzip pcspim.zip
4- Run SETUP.EXE

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Start & Setup SPIM

1. Run SPIM as shown in Figure(2).

Figure (2)

2. The message like in figure (3) will appear. Click the Yes button

Figure (3)

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

3. The window in figure (4) will appear

Figure (4)

If the path of exception file is not correct, change it to the correct path like
C:\Program Files (x86)\PCSpim\ exceptions.s by clicking on the Browse
and choosing the correct path. Then press the Ok button.

button

4. The main window of SPIM simulator will appear as shown in figure (5).

Figure (5)

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Setup the simulator


If the figure(4) in step 3 didnt appear , do the following to setup the Simulator
a- Open the simulator program, see step 1 and Figure(2).
b- When the main window appears, select the settings from Simulator
menu Figure (6).

Figure (6)

c-

The window will appear like in figure(4). Check the options as in this

figure

Create Assembly Programs to Run on SPIM


1. Type your assembly statements in a plain text editor
for example, use Notepad (under All Programs -> Accessories) or download
other text editors , install and open it.

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Some Text Editors:

Crimson Editor {http://download.cnet.com/Crimson-Editor/3000-2352_410031858.html}


Notepad plus { http://download.cnet.com/Notepad/3000-2352_410327521.html?tag=contentBody;pop}
-

2. Label your first statement "main:"


for example,
main: add $s0,$s1,$s2
3. Include at the end of your program
ori $2,$0,10
syscall

4. Save your program file with extension .s


for example: test.s

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Run Assembly Programs


1. Open the SPIM program.
2. Load test.s into SPIM:

3. Initialize the program registers:

CPCS-214 - The Lab Note

Lab. 1

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

try $s1=5, $s2=4

later you can use better ways to input data into programs

4. If input registers are loaded correctly, run program (otherwise return to last
step):

select menu item Simulator->Go, or press F5, or click the Go button on toolbar
.

CPCS-214 - The Lab Note

Lab. 1

10

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

5. Enter program command line parameters:


Simply click OK, or press ENTER (type the shown address if necessary)

6. "Registers" window (top part) shows final values of CPU registers.

note that $s0 holds the hex value 000000009 (decimal9) .

Problem? Simply relaod (select Simulator->Reload sample.s) and run again (back to 3a step 3
above). You may need to do that more than once.

CPCS-214 - The Lab Note

Lab. 1

11

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

Re-run Program
Select Simulator->Reload test.s then run it again with different values.

Run Program Step-by-Step


Don't forget to (re)initialize registers
1. Select menu item Simulator->Single Step, or press F10.
2. Press F10 repeatedly until the highlight is on line
jal 0x00400024 [main]
This instruction jumps to your program which begins at the line labeled main:

3. Press F10 repeatedly to step through your program.


4. Watch CPU registers change after each step.
in particular, watch the program counter (PC)

CPCS-214 - The Lab Note

Lab. 1

12

Spring
Term 2013

LAB 1: FAMILIARITY WITH SPIM Simulator and Text Editing programs

EXERCISE

Install the Windows version of SPIM and configure it to run


assembly programs.

Run small assembly programs in the SPIM environment.

Debug small assembly programs (step through, watch registers) in


the SPIM environment.

Write small assembly program using Mipster.

CPCS-214 - The Lab Note

Lab. 1

13

You might also like