

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


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.
Answer the following questions
SPIM Sample Program ###################################################################
####################################################################
.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
li $v0, 10 syscall
code.
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).