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
19
votes
2 answers

Why do we use .globl main in MIPS assembly language?

.text .globl main .ent main I don't know what .globl and .ent do. What is the role? Do I need to use globl. main and .ent main all the time?
Goodmorning
  • 193
  • 1
  • 1
  • 6
11
votes
2 answers

Reading and printing an integer in MIPS assembly language

My program is supposed to read an integer and print it back to the user, but every time it just prints 268501230, no matter what is entered. How can I fix it? .data prompt2: .asciiz "Please enter value: " array1: .space 40 array2: .space…
user2837034
  • 207
  • 1
  • 6
  • 11
9
votes
2 answers

Mips how to store user input string

I used to think I knew how to do this. But then I actually tried to do it. Here's the program I wrote but the Berkeley S*** simulator for mac said there was a syntax error on the last line. What did I do wrong? .text .globl __start …
jason dancks
  • 1,152
  • 3
  • 9
  • 29
8
votes
1 answer

Tweak mips-gcc output to work with MARS without using a script

The MIPS assembly code generated by mips-gcc almost, but doesn't quite, run on the MARS_ MIPS simulator. For example: The compiler generates "j $31" instead of "jr $31" The compiler puts .align directives in the text segment, which MARS does not…
Zack
  • 6,232
  • 8
  • 38
  • 68
7
votes
1 answer

Accessing one character in a string

I am using something like SPIMS or MARS with syscall functions. I am reading in a string (and it works because I can print it out) as follows: li $v0, 8 la $a0, string li $a1, 256 syscall However, I am having a problem accessing a single character…
darksky
  • 20,411
  • 61
  • 165
  • 254
7
votes
1 answer

Reading an integer into a local variable in MIPS

How can I read an integer into a local variable in MIPS? The problem asks me to use the concept of assigning integer variables as local variables. (A question from my text book.)
Mojo_Jojo
  • 939
  • 4
  • 13
  • 26
7
votes
0 answers

In a MIPS assembly `addi` instruction, how is a hexadecimal immediate interpreted?

Is there is a standard or recommendation for how the addi instruction (and others) should be interpreted in assembly, when hexadecimal immediate values are used? Example: addi $t0, $zero, 0xffff I was expecting this to mean the same as addi $t0,…
Miguel
  • 658
  • 1
  • 6
  • 19
7
votes
1 answer

Why is QtSPIM telling me "Label is defined for the second time"?

I am brand new to learning MIPS assembly code, and we got our first coding assignment. I am getting an error when I run my program (which is supposed to be a tester for another function we have to write) saying "spim: (parser) Label is defined for…
MathFlakes
  • 71
  • 1
  • 1
  • 4
7
votes
1 answer

Assembly MIPS - How do I store an integer from the user into memory?

So, I have no idea how assembly works or what I'm doing. I thought I did, but of course I was wrong. So here's my question - I don't even know how to let a user enter an integer so I can store it in memory. I also don't know if my variables are…
Eric Diviney
  • 327
  • 2
  • 5
  • 16
7
votes
2 answers

MIPS (or SPIM): Loading floating point numbers

I am working on a little mini compiler while trying to learn some MIPS here. Here's my issue: MIPS has an instruction li (load immediate) which would work like this li $5,100 which would load 100 into register 5. However, I need to load floats…
James
  • 572
  • 3
  • 9
  • 17
6
votes
4 answers

MIPS: Size of .asciiz?

When determining the size of .asciiz string, should I take into consideration the terminating character ? For example: .data string: .asciiz "Hello" The size of "string" is 5 or 6 (byte) ?
wonderingdev
  • 1,132
  • 15
  • 28
5
votes
1 answer

Reversing a string in MIPS Assembly

I'm trying to prompt the user for the length of a string, allocate space for that string, then print it out in reverse. For the life of me, I can't figure out why this isn't working.. Sample Output: (spim) run Please enter an integer: 7 …
user595334
5
votes
2 answers

C to MIPS translation

Trying to convert this c code into MIPS and run it in SPIM. int A[100], B[100]; for(i=1; i<100; 1++){ A[i] = A[i-1] + B[i]; } So far this is what I have. # comments are delimted by has marks .data A: .word 0:100 # array of 12…
user282964
  • 63
  • 1
  • 5
5
votes
3 answers

Getting result from mult in mips

I am new to assembly language, and I am really confused over multiplying. I was reading the quick tutorial here (dead link, web archive here) It says after I use mult $t0, $t1 the results are stored in Hi and Lo, I understand these are special…
Nick
  • 1,161
  • 1
  • 12
  • 22
5
votes
2 answers

LLVM/clang outputting to MIPS, but not working in SPIM

Given the file #include int main() { printf("hello world\n"); return 0; } I can use the commands clang -emit-llvm hello.c -c -o hello.bc llc hello.bc -march=mipsel -relocation-model=static -o hello.s to produce a nice…
Joe
  • 4,367
  • 7
  • 33
  • 52
1
2 3
14 15