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
0
votes
1 answer

How to concatenate two strings in MIPS?

concat: lb $t0, 0($a0) # $t0 = string1[i] beq $t0, $0, string2 # if end of string1, go to string2 sb $t0, 0($a2) # stringconcat[i] = string1[i] addi $a0, $a0, 1 #…
0
votes
1 answer

MIPS output includes previous output when running through program again

Hello I have a program that will alphabetize a 20 character string the user enters, while also filtering out characters that are not lower case letters. I have the program alphabetizing with a recursive loop, then have a more simple filter set up to…
0
votes
2 answers

MIPS assembly parsing error when trying to assign a variable

I am having problems with my MIPS assembly code. It shows a syntax error in li $t4, $zero line (4th line of the actual code). Could you help me solve it? .data .globl funcall1 .globl funcall2 .text funcall1: lw $t1,…
mashaned
  • 103
  • 11
0
votes
0 answers

Not stepping through byte string enough MIPS

I have an assignment where I have to take in a decimal number and output how many '1' bits are in the binary version. The number can't be greater than or equal to 4096 so we need error checking. We also have to use at least one logical operator. I…
0
votes
1 answer

Mips String Length, Concatenation and Copy-Display is Wrong

I am writing a Mips Assembly code for extra credit in my Computer Organization and Assembly Class. We are to take three strings(S1, S2, S3). Then we concatenate the three strings into another(S4 = S1+S2+S3). We also copy this string, so that S6 =…
user3408013
  • 1
  • 1
  • 1
0
votes
1 answer

Don't understand MIPS program

I don't understand the behaviour of this piece of MIPS code: .data x: .word 12 y: .word 14, -3 z: .ascii "CSE2021" t: .byte 0x8a v: .word y .text main: addi $t0, $0, 0 lw $s0, y($t0) lw $t0, v($0) lw $s0, -4($t0) jr $ra There are several things…
0
votes
1 answer

MIPS XSPIM different endianess order confusion

As a first time MIPS user I seem to be confused. I have some classmate who have said that there XSPIM is big endian. However, in Linux it is little endian byte order. If MIPS can be little endian or big-endian. Is there a way to find out in XSPIM if…
user3175173
  • 103
  • 2
  • 13
0
votes
2 answers

How to implement MIPS methods

Can I make a method and use it on an array? For example like this in java:bubbleSort(a), or is it only possible with jump to label stuff?
0
votes
1 answer

SPIM - Are register/memory values retained until SPIM is reinitialized?

So I'm turning in a project for class, and both parts of the program work. However I noticed: If I load the program (load "p5a.mal"), then execute it with run, it works. If I type run a second time, type the same input, it shows behavior that…
Lil' Bits
  • 898
  • 2
  • 9
  • 24
0
votes
1 answer

Mips exception at PC

Currently trying to develop a mips program for generating a math sequence. However, i keep getting a Mips exception at PC. terms: addi $sp, $sp, -12 #decrement the stack pointer by 12 sw $ra, 8($sp) sw $s1, 4($sp) sw $s0, 0($sp)…
Rob
  • 169
  • 1
  • 3
  • 12
0
votes
1 answer

Xspim simulator: transferring ints with mtc1

Code to transfer the integer 9 to the coprocessor, get the ceiling of its square root, then transfer this value back, and print it: addi $t1, $zero, 9 mtc1 $t1, $f0 sqrt.s $f0, $f0      # (*) ceil.w.s $f0, $f0   # (*) mfc1 $t0, $f0 addi $v0, $zero,…
gnometorule
  • 2,151
  • 2
  • 20
  • 29
0
votes
1 answer

For Loop in MIPS using .space

I am trying to make a loop that will add user inputted integers into an array until it fills the array. Every time I typed in a value, QTSPIM spits out 268501016 which I assume to be some random value stored in an register. To test if my program…
Doug_Doug
  • 3
  • 1
  • 2
0
votes
1 answer

MIPS Assembly: Immediate value is too large for field error

When trying to store a user's inputed string, for part of a project, I receive the following error in spim when I simply load the file: Immediate value is too large for field: [0x0040009c] Below is my code: .globl main .data prompt: .asciiz "0:…
0
votes
1 answer

Why is this MIPS assembly language code crashing my SPIM simulator?

In case the comments aren't too clear I'll describe what this is supposed to do. Takes two arrays of length 8 and multiplies each corresponding element and stores the product into a new array. In other words, for array1 [1,2,...,8] and array2…
WhyAyala
  • 647
  • 7
  • 29
0
votes
1 answer

Is my following code correct?

Are the commands correct with the corresponding comments? I'm having trouble understanding the mips assembly language such as what "Size", "Array", and "Result" means, also how I should incorporate them into my code. .text 0x00400000 .align…
June
  • 27
  • 4