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
1
vote
0 answers

In a MIPS program, how can you print the contents of the instruction memory in hex?

I was wondering if there was an easy method/code to display the contents of the instruction memory in hex format onto the the console in a MIPS program?
katebeckett
  • 71
  • 11
1
vote
1 answer

If/Else Statement on character strings from SPIM system calls

I'm writing a program in MIPS using Spim and I want to convert temperatures to/from fahrenheit and celsius. For example: Enter a number to convert: 100 Enter the Temperature: C 100 C is the same as 212 F So I'm having trouble getting the program…
Kyle2595
  • 193
  • 1
  • 6
  • 15
1
vote
1 answer

Can't load a word starting at x+4 address into registry in QtSpim

I want to load a word from memory ,at adress of x +4 into a registry but the following code doesn't work. What am I doing wrong? .data x: .word 10 y: .word 11 z: .word 12 .text main: lw $t0, x lw $t1,…
Ryncops
  • 189
  • 1
  • 14
1
vote
1 answer

Declaring more than one SPIM array causes a syntax error

Below is the beginning of a chunk of SPIM code: .data a: .space 20 b: .space 20 .text set_all: sw $ra,0($sp) li $t0,0 li $t1,10 ............ Unfortunately, the second array I declare ('b') causes the SPIM interpreter to…
zslayton
  • 51,416
  • 9
  • 35
  • 50
1
vote
2 answers

Finding the Max and Min values of a 10 element array in MIPS

I am still very much a newbie once it comes to MIPS programming so bear with me. I am trying to write a function that goes through a 10 element array and returns the max and minimum values of the array. So far I have: .data X .word 31, 17, 92,…
user3554599
  • 81
  • 1
  • 3
  • 13
1
vote
2 answers

Storing a very large string in a mips .asciiz

I want to store a string like this in the .data section in this type of of format: str: .asciiz "*************************************/n * */n * */n * …
user3718441
  • 85
  • 1
  • 3
  • 11
1
vote
1 answer

How does SPIM deal with incorrect types when reading from console?

I'm creating a MIPS simulator, and have come across a point that I think has multiple solutions. SPIM simulates reads from the console with syscall operations. I have used SPIM before but currently do not have access to it. How does it deal with…
Unilat
  • 341
  • 3
  • 10
1
vote
1 answer

Expand variable number of arguments in memory to argument space

I have a function that takes a memory address as $a0 and I access the (variable) number of words by using x($a0), where x is multiples of 8. I need to store these in the $sp register so I can use the $a0 register for passing arguments to other…
sff
  • 73
  • 3
1
vote
1 answer

String in MIPS and XSPIM conversion

Given a string let's say "Long Numbers" when I plug this in a ASCII calculator I am given this 0x4c 0x6f 0x6e 0x67 0x4e 0x75 0x6d 0x62 0x65 0x72 0x73 and 1001100110111111011101100111 1001110111010111011011100010110010111100101110011 It's my first…
user3175173
  • 103
  • 2
  • 13
1
vote
1 answer

ASM Language: Factorial Algorithm Error?

I can't seem to find where I am wrong in my algorithm, my specific problem is that i seem to print the same value for all integer inputted in the console: here is my code main: li $v0, 5 syscall jal factorial li $v0, 10 syscall factorial: …
1
vote
1 answer

Mips div.s syntax error

I am using QtSpim 9.9.1 to write my Computer Architecture course homework i had a syntax error when use div.s operator but it's OK when I use div. Another error appears when try to get float from user but it also disappears when get integer. Here…
Walid Ammar
  • 4,038
  • 3
  • 25
  • 48
1
vote
1 answer

read_char syscall not working correctly in command line spim

I wrote this simple program in MIPS assembly: .data .text main: li $v0, 12 # read_char syscall move $a0, $v0 li $v0, 11 # print_char syscall j main # repeat forever When I run it in QtSpim it works correctly: it takes a character from the console…
0x5C91
  • 3,360
  • 3
  • 31
  • 46
1
vote
1 answer

Finding a character of a string in MIPS

how would I find a particular character in a user inputed string that has a known length in MIPS? I've looked on SO as well as many other websites however, none can seem to fundamentally explain how to manipulate user inputed data. Here's what I…
Jay
  • 185
  • 2
  • 7
  • 21
1
vote
1 answer

MIPS "Unaligned address, Exception 5" error

I'm a noob using SPIM MIPS simulator. I get the error in title X 26 times, when I try to initialize an array of 26 words to 0. I've isolated the problem to be the store word operation sw $t0, 0($s3), but have no clue what am I doing wrong. The…
Israel
  • 1,184
  • 2
  • 13
  • 26
1
vote
2 answers

Opening another command line interpreter and typing commands

I use "spim" emulator to emulate the mips architecture. The way it works is that I should first have a "filename.asm" file, I then type "spim" in bash to open the command line interpreter for spim, then I can use the spim commands like loading the…
Keeto
  • 4,074
  • 9
  • 35
  • 58