Docsity

SPIM Homework: Getting Familiar with SPIM Simulator, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE2030 SPIM HOMEWORK
“Getting Familiar with SPIM”
DUE: Nov. 15, 2002
Type in the following program using a text editor (not a word processing package!) and execute it using PCSpim. PAY
ATTENTION TO THE SPACES IN THE ASCII DIRECTIVES! There is a bug in PCSpim: you have to leave a
blank line at the end of the program. To become familiar with the simulator it is useful to go through the following
sequence of steps.
• FIRST download simulator and run through the on-line tutorials in the NEXT Section of the notes labeled
PCSpim Tutorial
• Load the program into SPIM. If you typed it in correctly it should load with no errors. If there are
typographical errors then a dialog window will pop up with the line number. Other wise open the Console
window and you can check the error message. Continue to edit/load until all errors are taken care of.
• Run the program. Answer the questions in Problem #1 and see the results. The program should run with no
problem.
• Look in the data segment. It will be filled with values starting at address 0x10010000. These values are
product of the data directives in the program.
• Check the text segment. You will see instructions at each successive address in the text segment. Learn to
associate addresses with instructions.
• Open the registers window and you will see the contents of all 32 registers. Check the register’s contents
before and after running the program.
Answer the following questions
1. After loading the sample program on following page into the SPIM simulator, what are the contents of the second,
third, and fourth word in memory?
2. Indicate the type of computer you are using to run the SPIM simulator, and after looking at the contents of the data
segment, indicate if the machine uses big endian or little endian convention to store words.
3. How many bytes of data are being used in the data segment?
4. At what address does the data segment begin?
SPIM Sample Program
###################################################################
# INSERT YOUR NAME
# ECE 2030 ( E or F)
# SPIM Homework#1
####################################################################
# Comments begin with the ‘#’ character
# Begin the data segment (declare variables)
.data
.asciiz “SPIM is COOOOL!!!”
.byte 0xF2
.align 2 # enforce word alignment
.word 0xF28343AA
num1: .word 89
num2: .word 7
result: .word 0
result: .word 0
.text
lw $t0,num1
lw $t1,num2
add $t2, $t0, $t1
sub $t3,$t0,$t1
sw $t3, result1
sw $t4, result2
# end execution of the program
li $v0, 10
syscall
# A bug in SPIM requires you to have an extra carriage return after the last line of
code.
pf3

Partial preview of the text

Download SPIM Homework: Getting Familiar with SPIM Simulator and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

ECE2030 SPIM HOMEWORK

“Getting Familiar with SPIM”

DUE: Nov. 15, 2002

Type in the following program using a text editor (not a word processing package!) and execute it using PCSpim. PAY ATTENTION TO THE SPACES IN THE ASCII DIRECTIVES! There is a bug in PCSpim: you have to leave a blank line at the end of the program. To become familiar with the simulator it is useful to go through the following sequence of steps.

  • FIRST download simulator and run through the on-line tutorials in the NEXT Section of the notes labeled PCSpim Tutorial
  • Load the program into SPIM. If you typed it in correctly it should load with no errors. If there are typographical errors then a dialog window will pop up with the line number. Other wise open the Console window and you can check the error message. Continue to edit/load until all errors are taken care of.
  • Run the program. Answer the questions in Problem #1 and see the results. The program should run with no problem.
  • Look in the data segment. It will be filled with values starting at address 0x10010000. These values are product of the data directives in the program.
  • Check the text segment. You will see instructions at each successive address in the text segment. Learn to associate addresses with instructions.
  • Open the registers window and you will see the contents of all 32 registers. Check the register’s contents before and after running the program.

Answer the following questions

  1. After loading the sample program on following page into the SPIM simulator, what are the contents of the second, third, and fourth word in memory?
  2. Indicate the type of computer you are using to run the SPIM simulator, and after looking at the contents of the data segment, indicate if the machine uses big endian or little endian convention to store words.
  3. How many bytes of data are being used in the data segment?

4. At what address does the data segment begin?

SPIM Sample Program ###################################################################

INSERT YOUR NAME

ECE 2030 ( E or F)

SPIM Homework#

####################################################################

Comments begin with the ‘#’ character

Begin the data segment (declare variables)

.data .asciiz “SPIM is COOOOL!!!” .byte 0xF .align 2 # enforce word alignment .word 0xF28343AA num1: .word 89 num2: .word 7 result: .word 0 result: .word 0

.text lw $t0,num lw $t1,num add $t2, $t0, $t sub $t3,$t0,$t sw $t3, result sw $t4, result

end execution of the program

li $v0, 10 syscall

A bug in SPIM requires you to have an extra carriage return after the last line of

code.

PCSpim for Windows Tutorial

PCSpim for Windows is an emulator for the MIPS instruction set. You can download it from the following URL: ftp://ftp.cs.wisc.edu/pub/spim. You should get the “spimwin.exe” file from that location. SPIM allows you to run simple programs written in the MIPS assembly language. Your program can interact with the user with an emulated command prompt (the “console”). While your program is running, you can examine the state of the emulator including the data storage and the program being run. A local SPIM PCSPIM tutorial page is available at http://users.ece.gatech.edu/~sudha/2030/temp/spim-isa/spim-isa.html. Check the link to the tutorial page.

Note that SPIM doesn’t have a built-in text editor, so you’ll have to use Notepad or some other editor to create your assembly files. Assembly files are saved as plain text files with a “.s” file extension (e.g., “lab.s”). Each line of the file is either a comment, an instruction to the emulator, or a MIPS assembly instruction.

When a program is read in, it is divided into data and program code. The memory model used by the SPIM emulator has a “text” segment (where your program goes), a “data” segment (where declared variables are), and a “kernel.” The kernel code imitates the functions that an operating system would normally provide; you should never have to do anything with it.

Interaction between your emulated program and a user is accomplished with a window in SPIM called the “console” window. Special functions are provided for screen input and output.

MENUs in PCSpim Note: the menus have more options than the ones listed here. These are the options you’ll probably use most often. Feel free to play with the others.

FILE -open: This loads an assembly source code file (a .s file) and prepares the emulator to run it. The program will be put in the text segment and the data declarations will be put in the data segment. If you get an error window when you open your .s file, try opening the settings and turn off the loading of the trap file. If the message windows appears with syntax errors listed in it, you’ll have to correct your assembly code (using Notepad or another editor) and then try to open the file again.

-exit: Closes SPIM.

SIMULATOR -reload: Restarts the simulator and re-reads assembly file you have open. Use this if you run your program, make changes to it (in your editor), and want to run it again to see if the changes worked. Note that SPIM can sometimes get confused and reloading won’t fix it. In these cases, close SPIM completely and restart it.

-go: Starts running the program. It lets you choose what you want the program counter to start at (i.e., it lets you choose which line of code to start running at). Your program always begins at 0x00400000, the beginning of the text segment.

-break: This stops the assembly program wherever it might be. You can look at what values are held in data memory, the registers, and you can see what line of code was being executed. This is useful when you are debugging—especially if you think you are getting stuck in an infinite loop.

-single step: Run next instruction only, then break. Use this to watch register and data values change as your program runs and to see which instructions are being run. You can run a single step after breaking or to start the program at the first instruction (0x00400000).