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

MIPS if greater or equals to

if ($t4 >= $5) $t8 = $t8+1 Given that pseudo-code, I put this attempt together based on various sources. Seems simple but i am still learning the foundations. Not too sure if this is correct. slt $t1, $t5, $t4 beq $t0, $zero, endLoop addi $8,…
Mason
  • 173
  • 5
  • 23
1
vote
1 answer

MIPS instruction sll for array

Trying to understand how to do t0 = A[j-1] in MIPs by looking at an example of t1=A[j] Details 1. j is $s2, initialized to 5 2. i is $s1 3. Array is $s0 I have the example t1=A[j] MIPS sll $t3, $s2, 2 //I don't really understand why we need…
Mason
  • 173
  • 5
  • 23
1
vote
1 answer

How does a MIPS-32 linker convert lw and sw addresses?

I am reading Chapter 2.12 of Computer Organization and Design, trying to understand the logic of a MIPS-32 linker. I understand the concept of linking two object files and absolute reference linking. What I don't understand is the quoted paragraph…
Jordan
  • 902
  • 2
  • 10
  • 37
1
vote
1 answer

The MIPS offset plus base register addressing. How does it work?

I am confused at some text in my computer organization book: Let’s assume that A is an array of 100 words and that the compiler has associated the variables g and h with the registers $s1 and $s2 as before. Let’s also assume that the starting…
Jwan622
  • 11,015
  • 21
  • 88
  • 181
1
vote
1 answer

MIPS double precision immediates

I'm trying to create an equivalent of li for double-precision numbers. It seems like the following should work, but it doesn't: .main: li $t0, 0 li $t1, 5 mtc1 $t1, $f12 mtc1 $t0, $f13 li $v0, 3 syscall When I look at $f12…
Xodarap
  • 11,581
  • 11
  • 56
  • 94
1
vote
1 answer

Simple C function to MIPS instructions

I have a simple c function that I need to convert to MIPS instructions for a homework assignment. The function is: int load(int *ptr) { return *ptr; } my MIPS instruction I've come up with is: load: move $v0,$a0 jr $ra Is this…
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194
1
vote
3 answers

Is this MIPS strlen correctly converted from the corresponding C loop?

I have a simple question for a Comp Sci class I'm taking where my task is to convert a function into MIPS assembly language. I believe I have a correct answer but I want to verify it. This is the C function int strlen(char *s) { int len; …
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194
1
vote
1 answer

Optimized MIPS instructions from C returning immediately?

I've been playing around with Godbolt a bit to see how the compiler optimizes instructions, and something I've noticed is how the optimization of simple C programs seems to return immediately without actually doing the computation. Say I have a very…
rb612
  • 5,280
  • 3
  • 30
  • 68
1
vote
2 answers

Cross compiling not finding libs

I am trying to compile a piece of code on my Linux system (x86_64) for MIPS big endian architecture. Basically I followed this URL: https://www.linux-mips.org/wiki/Toolchains to get my own tool chain. I tried to compile software, configure phase is…
hap78
  • 29
  • 1
  • 3
1
vote
0 answers

Is 'early_printk' and 'early_con' related to a specific DT or board def?

The background is complex: I did an implementation of a complete FPGA SOC with a MIPS32r1 core, they're all written by VerilogHDL, so technically it's an unique "soft-board". It's running happily without any problem, I promise! Recently I'm…
1
vote
0 answers

Does the store word (sw) instruction in MIPS have dependencies on both the rt and rs field?

For example in a 5 stage pipeline with the following instruction set: add $t3, $t1, $t2 add $t6, $t4, $t5 sw $t3, 4($t6) //is there a dependency on $t3 and $t6? add $t6, $t6, $t3 //does the add have to wait until sw stores $t3 into the memory? I…
1
vote
1 answer

Double condition if statements in MIPS

I'm converting the following C code into MIPS and it appears that the isIdent function always return 0. C: full code here int isIdent (int m[N][N], int n) { for (int row = 0; row < n; row++) for (int col = 0; col < n; col++) …
pooroll
  • 33
  • 5
1
vote
1 answer

MIPS assembly code - trying to find out what this code's about

I'm learning assembly code, and given this code, I need to find what this code is about. However I am trying to debug using qtspim. I know what the value inside each register, but I still don't get what is this code about. If you find the pattern…
devss
  • 145
  • 8
1
vote
1 answer

What's the difference between SRL and SRA?

What changes when using the instruction sra and the srl one? I can't understand the difference between the two. The language in use is MIPS assembly. sll $t1,$t0,2 sra $t2,$t0,2 sll $t1,$t0,2 srl $t2,$t0,2
Corot
  • 33
  • 1
  • 1
  • 8
1
vote
0 answers

MIPS - Can a flush and stall happen simultaneously

Im studying for my microprocessors exam at the moment and I've come across this question: In relation to the below code: beq $1,$2, TARGET lw $3, 40($4) add $3, $3, $3 sw $3, 40($4) TARGET: or $10,$11,$12 Assume the branch…
cjjones1
  • 11
  • 1