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

Do you need to clear a register before using la in MIPS?

We are taught to always clear a register before using it, or to treat it as if it may already contain data that could affect the operation we are trying to perform on that register. If I use the la instruction, does it overwrite whatever was in that…
kocho84
  • 91
  • 1
  • 10
1
vote
1 answer

MIPS procedure calls failing

I'm working on an assignment for class where I'm supposed to find the sum 0 - n of a number n (example: sum 5 = 1+2+3+4+5). We had already done this for a previous assignment, and now the task is to implement a function call add2(int num1, int num2)…
1
vote
1 answer

Simple Array Manipulation MIPS Assembly

I'm new to MIPS assembly and I'm trying to learn how to use arrays. I understand that arrays are declared in the .data segment and then you load the address of the array to the register. However, I'm confused on accessing elements of the the array…
Ayelir
  • 41
  • 1
  • 1
  • 6
1
vote
1 answer

How can I avoid getting a negative random number from my function?

Here I am writing a function in MIPS assembly where the following function returns a random number within a given range. I know I could syscall 42 to do this but I am trying to learn from scratch. I use syscall 41 to get a random integer. The code…
PSIKLO
  • 27
  • 8
1
vote
1 answer

Bubble sort using MIPS by user input

I'm very new to MIPS. Ok, so my whole program is, about a user enters 10 integers and then we store it in an array, we then calculate the min and max and then print out the unsorted array. Then we begin the bubble sort algorithm where I'm struggling…
Nazar Trut
  • 35
  • 7
1
vote
1 answer

MIPS Direct Mapped Cache for Arrays

I need some clarity on how a direct mapped cache in MIPS works for an array. For example, for an array of ten items a[0] to a[9], and the following direct mapped cache configuration: Direct mapped cache with total cache size of 32 bytes and block…
Iva
  • 55
  • 3
1
vote
0 answers

What is the MIPS equivalent on these pseudoinstructions?

rol $t7, $t6, $t8 This is like: sll $t0, $t3, 8 # get rid of bits 31-23 srl $t1, $t3, 24 #move 31-32 to 7-0 or $t7, $t0, $t1 # do an or statement right? What about this one: ld $t2, 0($t8)
Jwan622
  • 11,015
  • 21
  • 88
  • 181
1
vote
0 answers

Does MIPS store offsets for sw and lw before or above the stack pointer?

This is a diagram in a class of mine and only instruction 0 has executed. In the stack on the lower right of that digram, it stores $ra at an address 4 less than the $sp which is at 128. In my book, however, they use offsets to mean higher than…
Jwan622
  • 11,015
  • 21
  • 88
  • 181
1
vote
0 answers

How to make my MIPS program more register efficient and readable

This is the C++ code I am trying to convert to MIPS with int count_painted(int *wall, int width, int radius, int coord) { int row = (coord & 0xffff0000) >> 16; int col = coord & 0x0000ffff; int value = 0; for (int row_offset = -radius;…
air bmx
  • 11
  • 1
  • 4
1
vote
1 answer

Symbolic Address vs Label in MIPS

I just want to be sure I'm being precise in my definitions. Is a program label just another term for a symbolic address or is it something different and more specific?
kocho84
  • 91
  • 1
  • 10
1
vote
1 answer

gcc cross-compile -mips1 not generating MIPS-I

I'm am targeting an old router need MIPS-I executables but -mips1 produces MIPS32 executables. Here is the compile command: buildroot-2019.02.5/output/host/bin/mips-linux-gcc-7.4.0 -march=mips1 -mtune=mips1 -static ~/helloworld.c -o /tmp/hw.1013 …
user570577
  • 109
  • 4
1
vote
1 answer

how to find min and max in an array MIPS

i can find the max perfectly fine but when it comes to finding the min, im having some trouble, my max finds the max number good but my min always prints out 0 no matter what, i cant seem to find out what is wrong with my code, does anyone see the…
Bob.Bob
  • 31
  • 1
  • 6
1
vote
2 answers

How to simplify MIPS ADD 1 / SLT / BNE into fewer Instructions?

How can these MIPS instructions be reduced to fewer instructions? addi $8, $3, 1 slt $9, $2, $8 bne $9, $0, End
1
vote
1 answer

MIPS, How do I find the decimal value in the immediate field of instruction

I'm working with MIPS in Mars. If I'm given the address of an instruction, how do I find the decimal value in the immediate field for the instruction. i.e. beq $t0, $t1, someLabel - at address (in decimal) 08
John
  • 77
  • 2
  • 11
1
vote
2 answers

Exercise in MIPS instructions

I'm new to MIPS, and we've done an exercise in class where we have to write a sequence of MIPS instructions that writes the value "-1" to the s6 register if the bit in the seventh position (from the right) of the register s0 is "1" (otherwise the…
Kevin
  • 427
  • 4
  • 12