Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to SPIM Simulator

Similar presentations


Presentation on theme: "Introduction to SPIM Simulator"— Presentation transcript:

1 Introduction to SPIM Simulator
Reference: Computer Organization and Design The Hardware/Software Interface David Patterson, John Hennessy 5th Edition, Morgan Kaufmann CDA3101 Spring 2018

2 How to install and use the QtSpim simulator
CDA3101 Peir / UF

3 Click on Download SPIM. This will lead you to the download page
Click on Download SPIM. This will lead you to the download page. (save in local disk!) CDA3101 Peir / UF

4 Click on the latest version for your operating system
Click on the latest version for your operating system. This will initialize a download. CDA3101 Peir / UF

5 Run the installation program
Run the installation program. For Linux: run the terminal command: “sudo dpkg -i <file location>” CDA3101 Peir / UF

6 Open QtSpim. QtSpim should now be installed and working on your machine.
CDA3101 Peir / UF

7 MIPS Program and Run it on QtSPIM
Write your program in a text editor. This can be anything (Notepad, WordPad, TextEdit, gedit, Sublime Text, Atom, etc) as long as the code is stored as plain text. NOTE, save your code with the “.s” extension!! CDA3101 Peir / UF

8 2. Open the code in QtSpim using
2. Open the code in QtSpim using Do not use the button: that load button appends your program to whatever’s already loaded in the simulator. CDA3101 Peir / UF

9 Click on to run your program.
Use to clear your registers and to reinitialize the simulator. Do this if you want to run your program again with a fresh simulator. To edit your program, go back to your text editor and modify your program. Save it, and reload it into the simulator using NOTE: you cannot edit your MIPS programs directly in the QtSpim simulator. You must use a text editor. CDA3101 Peir / UF

10 Data, Text Sections in SPIM Simulator
# data section .data # Create an array named "A" with 3 integers and assign values A: .word 89, 12, 54 # Store a string in data memory at location Str1 Str1: .asciiz "Sum of the three numbers = “ # text (program) section .text # Load the start address of array "A" into t0 la $t0, A # Other MIPS codes follow… CDA3101 Peir / UF

11 Start and Exit of Main Program
# text (program) section .text # define main program .global main main: # Load the start address of array "A" into t0 la $t0, A … # Exit program Li $v0, 10 syscall CDA3101 Peir / UF

12 System Call Example For example, to print "the answer = 5", use the commands: .data str: .asciiz "the answer = " .text li $v0, # $system call code for print_str la $a0, str # $address of string to print syscall # print the string li $v0, # $system call code for print_int li $a0, # $integer to print syscall # print it CDA3101 Peir / UF

13 CDA3101 Peir / UF

14 print int passes an integer and prints it on the console.
print float prints a single floating point number. print double prints a double precision number. print string passes a pointer to a null-terminated string read int, read float, and read double read an entire line of input up to and including a newline. read string has the same semantics as the Unix library routine fgets. It reads up to n - 1 characters into a buffer and terminates the string with a null byte. If there are fewer characters on the current line, it reads through the newline and again null-terminates the string. sbrk returns a pointer to a block of memory containing n additional bytes. exit stops a program from running. CDA3101 Peir / UF


Download ppt "Introduction to SPIM Simulator"

Similar presentations


Ads by Google