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

Does SPIM (MIPS simulator) always call the "main" label first?

I load up 2 files into SPIM in order. File 1: .globl getCount .data count: .word 50 .text getCount: lw $v0, count($0) jr $ra File 2: .text main: #code to call the getCount label and print the result stored in…
NoName
  • 9,824
  • 5
  • 32
  • 52
0
votes
0 answers

How to Print Hex Value in MIPS using SPIM Editor

I want to print hex value in MIPS using SPIM Simulation Editor, but I found some answers for MARS Simulation Editor. In MARS, I can do it as "li $v0, 34". How can I do this statement for SPIM editor? Thanks for helps.
Ufuk
  • 13
  • 1
  • 4
0
votes
1 answer

Mips first steps - Spim : syntax error

I am attending an university course that according to specification tries to follow book "Computer architecture a quantitative approach". Our task was to write an insert sort in MIPS, but I don't know how should I debug my code or even compile it.…
Ford O.
  • 1,394
  • 8
  • 25
0
votes
1 answer

MIPS: Aligning Output in Right Justified Columns

I am taking a class about how computers function on a lower level, mostly about memory management so far. Part of it is learning to write in Assembly Language using the PCSPIM simulator for MIPS processors. I just finished an assignment about…
Paul F.
  • 3
  • 3
0
votes
0 answers

Why this MIPS code don't show me the "a" occurrences?

I have a little problem with my MIPS code, because this not work with "a", I explain better... If I write: Heeeeello world --> I obtain this output "The 'e' has the biggest number of occurrences, 5" hi Maaaaaark --> I obtain this output "The '' has…
Marco
  • 49
  • 1
  • 11
0
votes
1 answer

Mips code with bug on the occurrences

I have find a way to solve my exercise but my code has a bug... With some phrases works good, with other no... I explain better with 2 example: aaaaabc ---> the letter '' has the biggest number of occurences, is present time. hello world! ---> the…
Marco
  • 49
  • 1
  • 11
0
votes
1 answer

Mips :verify if a matrix is symetric

How to verify if a matrix is symetric in mips ? .data string1: .asciiz "dati n \n" string2: .asciiz "dati elem matrice \n" n: .word 0 elem: .space 1024 .text main: li $v0,4 la $a0,string1 syscall li $v0,5 syscall sw $v0,n lw…
0
votes
1 answer

Syntax error when printing result using MIPS

I'm relatively new to MIPS and am using SPIM as my compiler. The program I am trying to write takes a user's input of a decimal integer and determines how many zero's and one's are in the binary representation of it: .data ques: .asciiz…
Root21
  • 31
  • 4
0
votes
1 answer

Finding Kth distinct element in an array MIPS

I am trying to write MIPS equivalent of the C code below. int arrayData[5] = { 1,2,1,3,4 }; int K = 3; int KCtr = 0; int result; bool isUnique; for (int o = 1; o < 5; o++) { isUnique = true; for (int i = 0; i < o; i++) { if…
Muhammet Ali Asan
  • 1,486
  • 22
  • 39
0
votes
1 answer

How do I add a constant to array items in MIPS

C code is this function foo() { int i,a[10],b[10],c=2; for (i=0; i<10; i++) a[i] = b[i] + c; printf (“%d\n”, i); } Here is my mips code: .data a: .space 10 n: .word 1 m: .word 10 .text main: la $t1, a la…
0
votes
2 answers

MIPS Branch Addressing Algorithm and Opcode isolation from instruction binary?

I just want to check my understanding of these two concepts is correct, as I have been trying to finish a project and while everything works to my expectations, it keeps narrowly failing the test cases and introducing a random value... Basically,…
0
votes
0 answers

How to convert decimal number to binary, octal and hexadecimal number in SPIM?

.data strIn: .asciiz "\nEnter a number:" reply: .asciiz "\nYour input is:" hexdigits: .asciiz "0123456789abcdef" hexword: .asciiz "00000000"` hexresult: .asciiz "\nHexadecimal code is:"` buffer: .space 10 .text .globl main main: #STEP 1 --…
0
votes
0 answers

Exception occurred with lw on MIPS SPIM

I wanted to load a word from the array, so I wrote: (a1 is a array pointer) addi $t4, $a0, 0 addi $t2, $0, 0 calL1: lw $t0, 0($t4) # t0 = $a1[i] addi $t4, $t4, 4 lw $t1, 0($t4) # t1 = $a1[i+1] add $t2,…
0
votes
0 answers

QtSpim Character Insertion

The program accepts a single-letter keyboard input at a time. The letter inputs must be lower case a through z (no upper-case or non-letter characters allowed; only lower-case letters). Only one letter must be input at a time; make sure that…
Lando
  • 1
  • 1
0
votes
1 answer

is it possible to add -1 value in add instruction in MIPS32

is it this instruction is correct Using SPIM ? add $t1,$zero,-1 after run program the $t1 is fill by "ffffffff"
Hary Coder
  • 13
  • 5