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

QtSpim Assembler: Error on stack operation with double

i'm writing a program for class. It takes x and epsilon from the console and should retrieve an sin(x) approximation. When i run it in QtSpim i get the error: Unknown instruction type: 0 The error occurs here: floatsin: addi $sp, $sp, -64 …
radiosonic
  • 35
  • 6
1
vote
1 answer

mips string copy: error in spim

Q1. In my class ppt, that codes are written, but the MIPS code does not work in SPIM. How can I revise the MIPS code? Q2. Assume that address of x and y are 100 and 200, respectively, and i = 10 and sp = 500. How can I revise MIPS code with that…
1
vote
1 answer

In MIPS assembly language, how does one round a floating point value to the nearest .01?

If I had the floating point (saved in some $f register) 1684.714 how could I round that to 1684.71? If I had the floating point 1684.716, how could I round that to 1684.72?
1
vote
0 answers

Print unsigned integer with SPIM?

This program calculates the Fibonacci sequence. How can i do it with unsigned number?( 'cause obviously I don't need negative number and if I use 2's complement I can't represent the 47th Fibonacci number I use qtspim and I can't use sys call 36 to…
Elisa
  • 19
  • 3
1
vote
0 answers

bubble sort using MIPS

This is a code for bubble sort in descending order using mips instructions. I keep getting the same error but I'm not sure what I am doing wrong. .data .align 4 Input_data: .word 2, 0, -7, -1, 3, 8, -4, 10 .word -9, -16, 15, 13, 1, 4,…
A.Lee
  • 11
  • 2
1
vote
0 answers

SPIM: Cannot open file

I used SPIM to simulate the following assembly code (MIPS). main: li $v0, 5 syscall move $a0, $v0 addi $t0, $zero, 1 addi $a1, $zero, 0 Loop: add $a1, $a1, $t0 addi $t0, $t0, 1 bne $t0, $a0, Loop move $a0, $a1 li $v0, 1 syscall li…
firewithin
  • 559
  • 1
  • 5
  • 12
1
vote
1 answer

Mips Output syscall

li $s5, 2 add $a0, $s5, $0 li $v0, 4 syscall Why system out is (null) in spim ?
Yanh Huan
  • 153
  • 2
  • 3
  • 6
1
vote
1 answer

How to check if two signed 32 bit integers cause overflow in MIPS?

I have figured out that for two unsigned integers, I can just do this: sll $a0, $a0, 31 #a0 is integer 1 to be added sll $a1, $a1, 31 #a1 is integer 2 add $t0, $a0, $a1 #result in $t0 addi $t1, $0, 2 beq $v0, $t0,…
mamajava
  • 75
  • 1
  • 7
1
vote
0 answers

Spim Syntax Parser Error

I have been working on this translation from HLL to MIPS AL for awhile now and I cannot figure out why I'm getting these syntax errors. I'll post the HLL I'm translating from and what is hopefully my near complete MIPS AL code. HLL: My Current MIPS…
CFalco
  • 19
  • 5
1
vote
1 answer

Why I have the error "store address not aligned on word boundary"

I have a problem with my MIPS code... I would check the occurrences in a string passed by keyboard without a character to compare. I have the string in the stack (stack -255 position) and an array in the .data section to store the occurrences. The…
Marco
  • 49
  • 1
  • 11
1
vote
1 answer

In MIPS32, when load address is called does the register receive all 4 addresses of the variable?

Assuming I have a variable which is a word, if I were to call la $t0, var Would the register now store 4 different addresses or just one? I am lost in regards to this as all the programming guides show that words are stored in 4 different 8 byte…
Kidkaos
  • 15
  • 4
1
vote
1 answer

Initializing .space in memory for assembly

How do I initialize this .space to zeroes? I want every single bit to be 0. My code subroutine: .data .align 2 memspace: .space 256 .text la $t7, memspace move $t2, $zero add $t2, $t2, 64 # should this be 256 / 4? confused loop: beq …
user3034572
  • 95
  • 1
  • 3
  • 9
1
vote
1 answer

Mips - print_string syscall doesn't work in -bare mode

This code is part of a much bigger program that worked just fine. Then I realized the assignment would be tested in -bare mode. As soon as I tried running it in -bare mode my print_string syscalls went from working fine to not printing anything…
1
vote
1 answer

checking if the value already exists in memory

I'm not sure how to do check a memory address and see if a word exists inside of the array. If I have the following code, where $t0 contains the base address of the array .data array: .space 800 #For 200 integers la $t0, table sw $t1, 0($t0) #Add…
1
vote
1 answer

Convert C++ Code to Assembly for SPIM

I'm having a lot of trouble getting my compiled assembly file working on SPIM. Basically I want to write a c++ file, and then generate a .s file that I can open in SPIM without error. This means that the assembly must be in MIPS32 ABI using MIPS I…
Dan Snyder
  • 1,483
  • 7
  • 20
  • 29