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

How to calculate MIPS using perf stat

Following answer about Benchmarking - How to count number of instructions sent to CPU to find consumed MIPS suggest that: perf stat ./my_program on Linux will use CPU performance counters to record how many instructions it ran, and how many core…
alper
  • 2,919
  • 9
  • 53
  • 102
1
vote
0 answers

Accessing a single character one by one?

I am trying to access a single character one by one in MIPS. Let's say the user enters 4624 or 45 — how would I access only 4 first, then 6 or 5, then 2, then 4?
bob
  • 11
  • 1
1
vote
2 answers

Overflow/carry flag in MIPS

I have searched a bit and didn't find anything that properly explained this. In MIPS you have add and addu to do additions. The main difference is that addu doesn't generate an overflow exceptions. Let's say we have this binary (I'm using four bits…
user4307777
1
vote
0 answers

How to write int to string in Mips

I'm asking a user for input and I want to replace each character of the word by the number of uppercase characters in this word Example: Input: AaAA output: 3333 (4 letters - 3 uppercase) The part for counting upercase letters in a word works…
sswwqqaa
  • 1,545
  • 3
  • 15
  • 29
1
vote
1 answer

How does MIPS store a number larger than 32 bits?

I was looking for an answer to this but couldn't find a clear one. Does it split the number between multiple registers or it can't simply cope with it? I tried testing it with MARS and using the number 4294967296 which is 0x100000000 but the…
PyFox
  • 383
  • 3
  • 11
1
vote
0 answers

remu instruction expanded to include break instruction - ALWAYS stops program

I'm learning MIPS by using QtSpim. In the code below, a remu pseudo-instruction is expanded to include a break instruction. I imagine that the break is to catch a divide by zero, but in this case, it stops the code from functioning regardless: …
sid
  • 157
  • 8
1
vote
0 answers

Mips have generic procedure?

I want to ask, if Mips assembly, have something similar to generic function, i understand that work with registers, and just need to load enother values, and go to procedure, but what if it's the same format of value? I will try to explain myself…
Alex Vartanov
  • 71
  • 1
  • 6
1
vote
0 answers

Game Maker Studio 2 : Android : Error in NDK : setup-app.mk

In Game Maker Studio 2, when trying to build for Android, I am getting the following error : ClangExeLocation=/Users/../Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ Using NDKDir =…
kris
  • 11,868
  • 9
  • 88
  • 110
1
vote
1 answer

splitting hexadecimal value in mips

I am working on a project where I need to take values contained in a hexadecimal value and split it. I will have a register that contains a value, 0xAA00BBCC and need to split it into 3 different integers, AA, BB, and CC For example: if the value…
austinm98
  • 15
  • 4
1
vote
0 answers

Unsigned subtraction, value still counts as less than 0

I was having troubles today with MIPS. I wanted to do something clever, and re-write this complex if-statement: if (c >= 'A' && c <= 'Z') as if ((unsigned) (c-'A') <= ('Z'-'A')) Here's C that works as I expect: #include int main(void)…
theonlygusti
  • 11,032
  • 11
  • 64
  • 119
1
vote
2 answers

How to cast to unsigned vector type after using __builtin_msa_ld_*

I'm evaluating MIPS SIMD Architecture (MSA) programming using the Codescape GCC Toolchain. There's not much information out there about MSA and builtins. (As far as I can tell there's only two MSA cpu's, the P5600 and Warrior I6400, and they first…
jww
  • 97,681
  • 90
  • 411
  • 885
1
vote
0 answers

MIPS - Having trouble finding the minimum value in an array

so I've been given an assignment in which I'm supposed to find the index of the max and min values in a user-created 10 digit array in MIPS assembly language. I've been able to find the max value but I'm having trouble finding the min value. I…
1
vote
1 answer

When writing in MIPS, I am unsure whether to use li or addi. I am still unclear what the difference is.

For example, I have a piece of C code that I am trying to convert to MIPS for practice, but for the variable count, I don't know whether to use addi $t0,0 or li $t0, 0. Could I use either either or? And what is the difference? Void haarPredict…
LiveToLearn
  • 163
  • 1
  • 2
  • 12
1
vote
1 answer

Simple MIPS for loop not running

I'm very new to MIPs and trying to create a for loop for an assignment. for (int i=1; i < 16; i+=2) { A[i] = A[i] + B[3*i] } With the current code I have when I try to load the value of A[i] it says fetch address not aligned on word…
Sauromayne
  • 105
  • 10
1
vote
0 answers

Single cycle mips, store word(sw) control values, why MemRead is 0 and not "don't care"?

I have a quick question, the book I have shows the control values for a store word instruction as such : Regdst - X Alusrc 1 Memto-reg X RegWrite 0 -> MemRead 0 MemWrite 1 Branch 0 ALUOp1 0 ALUOp2 0 The explanation for memto-reg to be "don't care"…
TG Person
  • 435
  • 4
  • 11