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

Difference between Assembler and Compiler

I was trying to learn MIPS Assembly language to understand better how computers work. I usually write Java and JS and I know that Java is using a compiler to execute my code. As I was learning MIPS I came across with the word assembler. How does…
keser
  • 2,472
  • 1
  • 12
  • 38
1
vote
0 answers

How to get a working bubble sort in MIPs assembly code?

I am having a few errors, the first one at lw $t3, 4($t7) I'm not sure if I'm accessing the array correctly or if I assign the array indexes to values wrong or what, but its not working and I get this error: Error in D:\bubble.asm line 77: Runtime…
Isaak Johnson
  • 129
  • 3
  • 8
1
vote
1 answer

MIPS conditional printing all cases

I am trying to determine the lowest of 3 numbers. I am using slt to compare 2 numbers at a time. I am using beq and bne, and comparing them to $zero (because the result of slt is either 0 or 1, and register $zero holds the constant 0). By using…
Bobemius
  • 21
  • 4
1
vote
0 answers

MIPS asembly, C - Why am I getting an undefined reference to main?

I am trying to compile this simple C file on a debian machine using gcc: #include char * my_name = "My Name"; extern unsigned int simple_op(unsigned int a, unsigned int b); void main() { unsigned int a, b, result; …
1
vote
1 answer

MIPS-Assembly: How to 'define' subroutine for later use

There are tons of great examples on how to properly follow MIPS function calling conventions. However, I'm getting stuck on how to use a function only when 'called'. The following will print 51 (using MARS): .data strproc: .asciiz "procedure…
lonious
  • 676
  • 9
  • 25
1
vote
1 answer

In which pipeline stage is branch decision been made?

In which RISC pipeline stage is branch decision been made? Is it in the "Decode" or "Executes" or other stages? Assume the pipeline have 5 stages - "IF", "ID", "EX", "MEM" and "WB".
user3489985
  • 327
  • 4
  • 18
1
vote
1 answer

Mips decimal to binary Spacing

Having difficulty with properly spacing the code. Can someone point me in the correct direction? should look like 0000 0000 instead of 0 0 0 0 0 0 0 0 I think im suppose to use the ascii space character but im implementing it…
MB2204
  • 9
  • 1
1
vote
0 answers

implementing this recursive function in MIPS

I have been given an assignment to recreate from C in MIPS. function1(n) = (3*n)-5 if n <= 3 function1(n) = (n-1)*function1(n-1) + function1(n-2) - n if n > 3 It is a recursive function which calls itself twice which is as follows: int…
1
vote
0 answers

MIPS Assembly Lanuage: Recursive Function Call

I wrote a simple code for a recursive function that does something like the following in C: Int function1(int n) { if (n <= 3) { int ans1 = (3*n)-5; return ans1; } else { int ans1 = (n-1)*function1(n-1)…
Jason Kwon
  • 11
  • 1
1
vote
0 answers

Assembly programming routine questions

I have to write two programs in assembly for class and I was just wondering whether you guys could help me understand what's being asked of me / any general tips on how to go about it. The first problem reads: Write your own routine to convert an…
conejo
  • 11
  • 3
1
vote
1 answer

2 shift operations in MIPS

The syntax for sll and srl is: sll $s0,$s1,n (n is an integer, for example sll $s0,$s1,3) srl $s0,$s1,n (n is an integer, for example srl $s0,$s1,3) I wonder if I can substitute $n$ for a register. For instance: sll $s0,$s1,$s2 I'm sorry, I'm a…
Tjh Thon
  • 85
  • 7
1
vote
1 answer

Stuck on a MIPS recursive function

I'm doing an assignment in MIPS and I feel like my logic is sound but I just can't get the code to produce the correct output. Can anyone look over what I've got and help? This is the corresponding function in C that I'm trying to implement. int…
Stefan S.
  • 11
  • 1
1
vote
1 answer

Which registers should be preserved in MIPS?

in MIPS which registers should be preserved on stack to prevent data loss. (T-S-A-V-RA REGISTERS)
Yunus Eren Güzel
  • 3,018
  • 11
  • 36
  • 63
1
vote
1 answer

MIPS - Are characters which are stored as bytes the same as those not stored as bytes?

I'm new to MIPS and I'm just wondering, I store a space character in the following ways: li $t0, ' ' lb $t1, ' ' la $t2, myArray # load array sb $t0, 0($t2) # myArray[0] = ' ' In this case is $t0 == $t1? And is the sb instruction valid? What…
user10284022
  • 65
  • 1
  • 7
1
vote
3 answers

Questions about MIPS Codes

How to write the following into MIPS instructions? $t0=$t1 if ($t6<$t7) go to Label.
user644441
  • 11
  • 3