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 How can I calculate numbers greater than 1.111 x2^1023?

I'm working with MIPS and MARS 4.5. Is there any way to calculate numbers that extend the range of 1.111.. * 2^1023? For example (factorial func): .data dval: .double 171.0 # its working up to 170! one: .double 1.0 .text …
vP3nguin
  • 320
  • 6
  • 18
1
vote
1 answer

About data hazard and forwarding with beq in MIPS?

Why the first add needs forwarding? # stage: add $1, $2, $3 # WB add $4, $5, $6 # MEM nop # EX beq $1, $4, target # ID Since beq needs the $1, if the first add is about to execute WB-stage, isn't that…
Kindred
  • 1,229
  • 14
  • 41
1
vote
1 answer

MIPS array indexing using a displacement in lw for a known constant index?

I am trying to translate from C this line of code of a nested array p=A[B[6]] that I've found on the book I'm studying MIPS from. Because I am pretty sure that the solution from the book is wrong or, at least, much more complicated than what it…
Anna
  • 83
  • 1
  • 7
1
vote
1 answer

I can't understand a portion of code from a MIPS problem

So, I have a problem which translates a C program that calculates the sum of n numbers with a function with a variable number of parameters. #include int sum(int n, ...){ int i,s; va_list l; va_start(l,n); s=0; …
1
vote
1 answer

array on MIPS Assembly

I'm trying to write a mips function which return the position of the maximum value but I'm getting this exeption (Error in /home/ams/Bureau/part2a line 21: Runtime exception at 0x00400028: address out of range 0x00000000) # MIPS assembly code # $s0…
Mooh
  • 1,237
  • 3
  • 19
  • 38
1
vote
0 answers

Why does this load instruction come after a jump?

Let me preface this by saying that I'm new to MIPS. I'm trying to reverse some sample code that I compiled for PSX using Psy-Q. I compiled a small "hello world" program that happens to contain the following function call in C int main() { …
Ci3
  • 4,632
  • 10
  • 34
  • 44
1
vote
0 answers

MIPS program with recursion

This is my last assignment for this semester. I need to convert a base 33 number to base 10 (this part is working) and it needs to be done with recursions (this part is not working). I wrote this code, but I am getting an error, called "Exception…
EAP
  • 31
  • 1
  • 8
1
vote
1 answer

MIPS Assembly while loop

I am currently learning MIPS and while doing some exercises I came across one which is to write the Fibonacci sequence first in Java then convert it to MIPS Assembly. I only can use beq, bne and slt My Java code is the following: int n = 50;…
user9318203
1
vote
1 answer

About MIPS lb and sb and endianness

I just read a comment by @Cheshar in this answer - Loading and storing bytes in MIPS. This is my reasoning regarding his first point: the value in $t0 should be 0xFFFFFF90 (i.e. it's sign-extended) but this won't change the result of mem(4) (I…
Kindred
  • 1,229
  • 14
  • 41
1
vote
1 answer

Mips Assembly toggle case

I'm trying to toggle a simple user given text from lower case to upper and vice versa. Example: “Hello” after running it becomes “hELLO” essentially toggling cases. The program currently only converts from lower case to upper. My question is, how…
pyfs
  • 13
  • 4
1
vote
1 answer

MIPS Instruction Decoding

I'm trying to understand how to decode MIPS binary instructions. I compiled a hello world program in C on a Debian MIPS system with gcc and objdump shows me that the first instruction in the .text section is: 600: 03e00025 move zero,ra I…
Stefan
  • 675
  • 3
  • 9
1
vote
2 answers

MIPS jump and BNE address calculation

Suppose the program counter (PC) is set to 0x20000000.Is it possible to use the jump (j) MIPS assembly instruction to set the PC to the address 0x40000000? Is it possible to use the branch-on-equal (beq) MIPS assembly instruction to set the PC to…
Hasin Sadique
  • 17
  • 1
  • 6
1
vote
0 answers

MIPS beginner: count amount of 0s in array

Can someone help me with my MIPS code? I don't get why it doesn't work. I want to count the amount of zeroes in my array. Am I not traversing my array correctly? .data array: .word 20, 0, 3, 0, 0, -4, 0, -30, 120, 0, 0 # array of…
Nana
  • 11
  • 2
1
vote
0 answers

Hollow Square in MIPS assembly

I am having trouble with the following MIPS assembly code, What I want to do is take the following C code and make this in MIPS Assembly(MARS 4.5). /* Input number of rows from user */ printf("Enter number of rows: "); scanf("%d", &N); …
Juan
  • 19
  • 2
1
vote
1 answer

Encoding basic instruction formats in MIPS

I'd like to figure out how to encode BASIC INSTRUCTION FORMATS referred to in the MIPS Green Sheet e.g. I'd like to encode the instruction add $t0 $t1, $t2. I know that the Format is R; opcode will be 0x0; The Funct 0x20. But how will I get the code…