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

MIPS: Reading a string from command line argument

I'm new to Assembly. I'm having some trouble reading a string from the command line arguments. I would like to read the string thisismymessage from the 2nd argument into a buffer. I thought of using SYSCALL, but not sure how. $ spim -f program.s…
Joel
  • 161
  • 1
  • 3
  • 12
4
votes
1 answer

Specify MARS Input File

I'm testing a MIPS Assembly program in MARS, and would like to specify a file to take as input during execution (sort of like what I can accomplish by redirecting stdin with the following UNIX command): spim -file [filename].s < [input_file] Is…
BraedenP
  • 7,125
  • 4
  • 33
  • 42
4
votes
1 answer

mips memory management

how do you manually manage the heap in mips assembly, specifically the SPIM simulator? the heap, i've found begins at 0x10040000 when using the sbrk syscall, e.g. li $t0, 1 li $s0, 9 syscall sw $t0, ($s0) # 1 located at 0x10040000 so, does a call…
dnbwise
  • 55
  • 1
  • 5
4
votes
0 answers

MIPS while loop error

I am having some trouble with the following mips code: li $t0, -1 li $t5, 0 countNumberofVariables: addi $t0, $t0, 1 beq $t0, $t8, endCount add $t1, $t0, $t9 lb $t1, ($t1) li $t2, 10 beq…
David Watson
  • 2,031
  • 2
  • 13
  • 17
4
votes
2 answers

sample spim code

I found this sample spim code on the internet .data COUNT: .word 10 TEXT: .asciiz "The number is " EOL: .asciiz "\n" .text .globl main main: addiu $sp, $sp, -32 # Adjust stack sw $ra, 24($sp) sw $fp, 16($sp)…
user591931
  • 239
  • 2
  • 3
  • 10
4
votes
2 answers

What is the proper behavior of 'jalr $a0, $a0'?

I came across the instruction jalr $t1, $t2 instruction, which supposedly sets $t1 to the return address and jumps to $t2. However, there seems to be some ambiguity as to which operation happens first. For instance, the following works differently…
Frxstrem
  • 38,761
  • 9
  • 79
  • 119
3
votes
3 answers

Storing values in HI and LO registers of MIPS

I am writing certain code in MIPS and I've come to the point where the requirement is to store the result, temporarily, in HI and LO special registers (both are 4 bytes wide). These instructions are at my disposal: divu s,t lo <-- s div t ;…
DV.
  • 4,585
  • 9
  • 37
  • 44
3
votes
1 answer

I get the error MIPS “spim: (parser) syntax error” when running the code

I'm using a MIPS simulator. Occurs that when I'm trying to open the text file that contains my code in the simulator I am having trouble understanding why this will not run on QTSpim. I get the error spim: (parser) syntax error line 8 Code: #This…
bobbyjon
  • 31
  • 1
  • 2
3
votes
1 answer

Access MIPS Co-processor condition flag directly

I wish to access the value of the MIPS coprocessor 1 condition flag. For example c.eq.s $f4 $f6 move $t0 condflag1 #clearly illegal I understand that the following is possible: c.eq.s $f4 $f6 bc1f L_CondFalse li $t0 0 j L_CondEnd L_CondFalse :…
Jason
  • 211
  • 5
  • 10
3
votes
3 answers

ELF File Format

I'm attempting to manually load the hexdump of an elf file that I compiled using g++ into a processor simulation I designed. There are 30 sections to a standard elf file and I am loading all 30 segments with their proper memory location offset taken…
Dan Snyder
  • 1,483
  • 7
  • 20
  • 29
3
votes
1 answer

MIPS dynamic memory allocation using sbrk

I was trying to use sbrk for dynamic memory allocation. But, being a newcomer to SPIM and MIPS, I was unable to do so. I sketched out a rough code for the same. .data var: .word 25 .text main: li $v0, 9 la $v0, var …
Sahil Babbar
  • 143
  • 1
  • 2
  • 8
2
votes
1 answer

Whats wrong with this MIPS/QtSPIM While Loop Code

The programs runs with expected output but with the errors below Code .data .text .globl main main: addi $t0, $t0, 0 # i = 0 addi $t2, $0, 10 # n = 10 j WhileCond # goto WhileCond WhileLoop: li $v0, 1 #…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
2
votes
1 answer

Expressing this statement in MIPS

I've just started on MIPS with SPIM simulator. Can someone help me converting this statement ? if(as>47 && as<58) function(); else continue; Thanx in advance. :)
Mojo_Jojo
  • 939
  • 4
  • 13
  • 26
2
votes
1 answer

Trouble with MIPS macros in SPIM

I'm struggling to get a macro to work in my lab code. This is how I wrote it: .macro print_char($arg) li $v0, 11 add $a0, $zero, $arg syscall .end_macro I don't think it should matter where it is relative to other labels but it is after…
polar
  • 194
  • 1
  • 15
2
votes
0 answers

How to pass arguments in SPIM CLI's interactive debugging mode?

I know that we can do this to pass arg_inp_file.bin as an arg to the MIPS program: spim -file myfile.s arg_inp_file.bin But this loads the argument and starts executing right away. How can I achieve the same, using the interactive mode, like after I…
Samuel Bushi
  • 341
  • 3
  • 16
1
2
3
14 15