Questions tagged [mips]

MIPS is a RISC instruction set architecture (ISA). It is commonly used in embedded devices such as set top boxes and networking gear. Many university-level computer architecture classes use the MIPS ISA due to its relative simplicity. If your question is about MIPS assembly and machine code, also add the assembly tag.

MIPS is a common RISC (Reduced Instruction Set Computer) ISA (Instruction Set Architecture), one of the first of its kind, and early MIPS is still used as an example of a classic RISC 5-stage pipeline. MIPS originally stood for "Microprocessor without Interlocked Pipeline Stages", though modern MIPS implementations now have interlocked pipeline stages.

Stack Overflow's tag gets about MIPS-like simple CPUs, and questions about programming it. In both cases, it's common to ask about simplified MIPS CPUs that don't use a branch-delay slot because that's what students are often working with, unlike actual commercial MIPS CPUs and the actual MIPS ISA. The MARS and SPIM simulators are configured by default to simulate a MIPS without branch-delay. (And the majority of MIPS assembly programming questions on Stack Overflow are about programming in that environment with their toy system calls as well, which implement things like print integer or read integer, things which on a real-world system would be done by C library functions.)

MIPS processors have two flavours: both big-endian and little-endian (often referred to as mipsel), so it might be useful to apply one of those tags as well. Many common modern System-on-chip processors that run Linux and are often found in devices such as consumer routers / Wi-Fi devices, IP cameras and other embedded systems employ MIPS architecture, including many Broadcom, Atheros and Ralink SOC.

Overview:

  • Wikipedia overview: history, CPU families, instruction format, register usage conventions
  • MIPS 32 architecture: manufacturer summary and links to reference manuals
  • MIPS 64 architecture: ditto for 64-bit CPUs (navbar has links for microMIPS, DSP ASE, MT, SmartMIPS, MIPS16, MIPS-3D, and MCU ASE)

Instruction set references:

  • MIPS32™ Architecture For Programmers Volume II: The MIPS32™ Instruction Set is the name of the document that lists and describes all instructions in the MIPS32 instruction set, along with their encodings. It can be found through the MIPS 32 architecture link above, or through a search engine.

  • MIPS64™ Architecture For Programmers Volume II: The MIPS64™ Instruction Set is the name of the same document for the MIPS64 instruction set.

  • MIPS R3000 manual (MIPS I) from 1994. Chapter 9 includes an instruction-set table (including expansions for pseudo-instructions) and C syntax for what it does. Handy to see sequences for abs and neg, as well as which instructions are real machine instructions.

  • See MIPS Run, especially Chapter 8. Complete Guide to the MIPS Instruction Set. Table 8.6 has encodings and when each instruction was introduced. (MIPS II, III, IV, and some special instructions on specific MIPS chips.) It includes TLB-maintenance instructions, MIPS II branch-likely instructions (branch-delay slot NOPed when not taken), and floating point (FP) instructions. It's a real book, so it has whole sections of explanation of how to use / how it works / why it makes sense for things like the unaligned-load instructions. But it doesn't have MIPS32 or anything newer than MIPS IV, it seems.

  • Instruction-set quick reference: MIPS Green sheet from Patterson & Hennessy's textbook. This is quite good, but is not complete even for classic MIPS I integer instructions. It omits real machine instructions including at least bgezal, and even non-linking compare-reg-against-zero instructions bltz/blez/bgtz/bgez. This video by University of Illinois professor Geoffrey Herman walks through how to read the notation for what each instruction does, and what the machine encoding is.

Running / debugging MIPS assembly code:

University / college courses that involve MIPS assembly language programming often make use of MIPS simulators such as or to allow students to run their programs. These simulators include debugging features like single-stepping, breakpoints, and register/memory viewers, that helps developers understand the runtime behaviour of their code.

Before posting a question asking for debugging help you should attempt to debug your program yourself. Even if you're unsuccessful in finding the bugs, your initial debugging attempt will probably have helped you narrow down the potential problem sources, and get a better understanding of your own code. Your findings should be detailed in your question, so that people attempting to answer your question won't have to duplicate your work.


Useful / basic Q&As about assembly programming

Q&As about internal data-paths / CPU-architecture / ISA-design

5808 questions
1
vote
1 answer

write russian peasant multiplication with mips

i want to write a program that use russian peasant multiplication with mips but i face some problems / A method to multiply two numbers using Russian Peasant method unsigned int russianPeasant(unsigned int a, unsigned int b) { int…
user3001977
1
vote
1 answer

Changing a Character in Data Segment

I want to change a character in a string. For that I load in $t2 the char which is representing a hit. In this example the " " char at the 7th position should change to a "x". After trying to updating my board with sh $t2, 0($t0) I get the following…
Richie
  • 73
  • 1
  • 6
1
vote
2 answers

Translating C function with args to MIPS: loop over an int array and count negatives

My question is about procedures in MIPS and using arguments. I'm trying to translate this small C Function to MIPS and I wasn't sure if I was in the right track. This is the C function: 0 int countNegatives(int table[] , int n) { 1 int count =…
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

Interpretation of IEEE-754 doubles between machines

I have two machines, one is a MIPSPro machine running IRIX and the other one is an x86_64 machine running RHEL 6.7. In both of these machines I am reading a binary stream of data and converting each 8 bytes to a doubles. I.e both doubles contain…
Iliketoproveit
  • 445
  • 6
  • 15
1
vote
1 answer

terminate mips assembly programm mit jr $ra

Normally I would terminate my programm with li $v0, 10 syscall Now I've seen many code examples where they terminate the programm by jumping back to the $ra register. jr $ra Why is this possible to terminate the program like…
Richie
  • 73
  • 1
  • 6
1
vote
1 answer

Runtime exception at 0x00400014: address out of range 0x7fbffffc

I am trying to write a recursive function that prints numbers from 1 up to X, but I get this error, specifically at sw $a0, 0($sp). .data .text # Getting user input li $v0, 5 syscall move $a0, $v0 PrintUp: addi $sp, $sp, -8 #make a…
1
vote
0 answers

(MIPS) How can I identify and compare a string stored in a .word

I am really struggling with the wording of a project I am working on. For mips they are requesting that I take in two arguments before launch. I store both of them into .word memory addresses. However, it then asks me to treat them as though they…
Matt
  • 11
  • 2
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
1 answer

Printing the nth term in an array

I've created an array lookupTable: .float 0, -0.001592654936407223, 1255.7655915007897, 1.72992922008979, 0.9992039901050427, 0.7260559689601765, 0.5769964003928729, 0.4812943620193547, 0.41398034288365404, 0.36376984280336827,…
Harmony
  • 99
  • 2
  • 9
1
vote
2 answers

Trouble with assembly language homework

I thought I correctly implemented a while loop, but why am I not getting any output? My book isn't that great of a help, and I haven't been able to find a resource online. ##### The Data Segment ######### .data strFirstNumber: .asciiz "Enter…
bdmflyer
  • 145
  • 11
1
vote
1 answer

Syntax error in MIPS?

So, I'm currently learning MIPS for my Uni degree and I've came across a syntax error that is bugging me, I can't seem to put my finger on where I went wrong, my piece of code is one where a user enters two numbers, and the console is supposed to…
AlonErebos
  • 17
  • 6
1
vote
2 answers

RISCV Instruction set simulator

I'm look for instruction set simulator for CPU based on RISC-V. I want to observe the hazard on different CPUs (RISCV and MIPS). This example is for MIPS. lw r1,A(r2) lw r3,B(r4) dadd r5,r1,r3 beq r5,r5,L1 sw r5,A(r3) L1: sw r5,B(r4) beq must be…
Barry
  • 21
  • 4
1
vote
0 answers

What does 'pc = pc+4+BranchAddr' mean?

I was doing this question: The following instruction is not included in the MIPS instruction set: rpt $t2, loop # if(R[rs]>0) R[rs]=R[rs]−1, PC=PC+4+BranchAddr (note, BranchAddr is the encoded value that is used to calculate target “loop”…
Yinghan Ma
  • 51
  • 7
1
vote
0 answers

converting c recursion code to mips

I am in the process of trying to convert this C code to MIPS. This is only my second project so far and I feel like I am so close. Here is the C code. //fast modular exponentiation int fme(int x, int k, int n) { int temp; int result = 1; …
Timdoozy
  • 21
  • 2
1 2 3
99
100