Questions tagged [spim]

spim is a self-contained simulator that runs [tag:mips32] programs

It reads and executes assembly language programs written for this processor. Also provides a simple debugger and minimal set of operating system services. It does not execute binary (compiled) programs.

Spim implements almost the entire MIPS32 assembler-extended instruction set. (It omits most floating point comparisons and rounding modes and the memory system page tables.) The MIPS architecture has several variants that differ in various ways (e.g., the MIPS64 architecture supports 64-bit integers and addresses), which means that Spim will not run programs for all MIPS processors.

Spim implements both a terminal and windows interfaces. On Microsoft Windows, Linux, and Mac OS X, the spim program offers a simple terminal interface and the QtSpim program provides the windowing interface. The older programs xspim and PCSpim provide window interfaces for these systems as well.

Read more

System call information:

SPIM simulates a number of operating system-level functions for console I/O (e.g. print_int, print_string, read_string), file I/O (e.g. open, read), dynamic memory allocation (sbrk), etc. These functions are invoked by setting up the CPU registers according to the SPIM system call documentation and then executing a syscall instruction.

Branch delay slots:

Quoting from MIPS32™ Architecture For Programmers Volume I: Introduction to the MIPS32™ Architecture":

All branches have an architectural delay of one instruction. The instruction immediately following a branch is said to be in the branch delay slot.

In English: The instruction directly following a branch (jump) instruction will be executed before execution continues at the address you're branching to.
When writing MIPS assembly language code, care needs to be taken to fill the branch delay slots, either with NOPs, or with more meaningful instructions by changing the order or some instructions.
Note, however, that SPIM doesn't simulate branch delay slots by default. If simulating branch delay slots is desirable, it can be enabled in "Simulator" -> "Settings.." (PCSpim) or "Simulator" -> "Settings" -> "MIPS" (QtSpim). Enabling the "Bare machine" option also enables branch delay slot simulation.

218 questions
2
votes
3 answers

using multiple mips arguments >4

Im trying to program a function to use extra arguments besides 4 (since my version of mips only supports $a0-$a3) by pushing them on the stack, but my code is incorrect. Here is my code in main (snippet): li $t0,40 #temp value for our 5th arg. addi…
jfisk
  • 6,125
  • 20
  • 77
  • 113
1
vote
0 answers

Assembly Generating Sound in QtSpim

My friends and I are thinking about trying to write a music-composition engine in assembly. We are required by our course to use QtSpim and wanted to know how to generate sound. In MARS, Assembly has access to the sound card via syscalls: …
Andrew Latham
  • 5,982
  • 14
  • 47
  • 87
1
vote
4 answers

SPIM (MIPS Simulator) is unable to parse the following statement lui $2,%hi($LC0)

We are developing a C to MIPS cross compiler, and for that we need to compare our MIPS code with the code generated by other C to MIPS cross compiler like LLVM, or CodeSourcery, etc. We are using SPIM to run our MIPS code. Right now we are using…
Vikash Joshi
  • 21
  • 1
  • 6
1
vote
1 answer

Measure execution time, using SPIM

I need to measure execution time of Hanoi Towers program, written in assembly language. Is there any function or specific register value used to do this task..?
Alba Xhani
  • 11
  • 1
  • 3
1
vote
0 answers

Real Mode x86 simulator similar to SPIM?

I am looking for a Real Mode x86 simulator similar in principle to the MIPS32 simulator "SPIM". Ideally, it would also support 286 Protected Mode (32 bit Protected Mode is less important). Anyone know such a beast?
Andrew J. Brehm
  • 4,448
  • 8
  • 45
  • 70
1
vote
1 answer

spim simulator pcspim : error setting value at an address

Hi I am using spim simulator pcspim and I am trying to set a value at an address using the set value option under the simulator menu. When I try to set a value which has an msb of 1 for ex. oxb1234567 the value at that address is defaulted to…
koool
  • 15,157
  • 11
  • 45
  • 60
1
vote
2 answers

Spim Instruction division

[0x00400000] 0x3c011000 lui $1, 4096 ; 5: li $t0, 0x100000F4 [0x00400004] 0x342800f4 ori $8, $1, 244 [0x00400008] 0x8d100000 lw $16, 0($8) ; 6: lw $s0, 0($t0) the above is my spim program, I am…
coool killer
  • 23
  • 1
  • 5
1
vote
1 answer

Why A and B registers are used in multicycle Datapath?

Why are registers A and B whose inputs are ReadData1 and ReadData2 of RegisterFile are necessary? Isn't it possible to use directly the values which are on ReadData1 and ReadData2 outputs of Register File? Instruction Register is already loaded with…
Valikeny
  • 59
  • 4
1
vote
1 answer

How do you enter command line arguments in SPIM

I am trying to make programs using argc and argv in MIPS simulator SPIM. This is my code: .data nl: .asciiz "\n" .globl main .text main: # print argv[0] lw $a0, 0($a1) li $v0, 4 syscall # print "\n" li $v0, 4 la $a0, nl syscall #…
1
vote
1 answer

Why am I getting spim: (parser) Label is defined for the second time on line 7 of file when running my program?

I'm using QtSpim to make a quick program that's supposed to perform two bitwise ori operations on some integers. When I try to assemble the program, it gives me this error message, saying I can't use the same label twice - this is the exact code…
Zonk
  • 11
  • 1
1
vote
2 answers

How to use pointer correctly in MIPS?

I wrote a program which takes input of a few numbers and loops through every one. Then it should swap the maximum if the current number is bigger than my last max one. If it's at the last number (at the end of my string), it should exit. I'm trying…
Andre
  • 35
  • 1
  • 6
1
vote
1 answer

QtSPIM MIPS Simulator: Register a1 and a2 get automatically changed

The QtSPIM MIPS simulator automatically sets the registers a1 and a2 to the following values upon execution of the first line of any assembler program: R5 [a1] = 7ffff57c R6 [a2] = 7ffff584 What is the reason for that? Is there a way to avoid it?
NicolasBourbaki
  • 853
  • 1
  • 6
  • 19
1
vote
0 answers

Program to convert temperature from F to C

I'm writing a program to convert temperature from F to C in MIPS but the compiler returns 0. It works when I do it with integers, any ideas on what could be wrong? Code Section .text main: # Print msg la $4, input_msg li …
acelifter
  • 11
  • 3
1
vote
0 answers

How to fix bad address error in MIPS assembly

I am very new to MIPs programming and have been struggling alone to solve to problem. I am in need of help from people of expertise, to help me through the way. I am trying to build a program that takes in multiple integer inputs from the console…
jamesdean
  • 21
  • 5
1
vote
0 answers

MIPS Input validation - how to read ints and text

I've been learning a bit about MIPS and I'm required to write a Factorial program that takes in input and prints out nth Factorial. Positive integers are not a problem, and their spec requires me to print 1 for negative input which is fine since…
Calahan
  • 35
  • 6