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

what is int f(int n,int m) in MIPS

I working on translating some C code to MIPS and got stuck on this one line. int f(int n, int m) I know this is supposed to be for initializing the variables but how would it look like in MIPS? I'm having n=$a0 and m=$a1. For Context here is the…
iray1995
  • 11
  • 2
1
vote
0 answers

How to convert a binary string to its 2's complement in MIPS Assembly?

I have a MIPS Assembly program that takes in a negative integer from user input, finds the absolute value of that number, then converts it to a binary string. I want to be able to find the 2's complement of the number by flipping the binary string…
Ed Delacruz
  • 87
  • 11
1
vote
1 answer

MIPS Branch instruction jumping beyond range

I understand that in MIPs for PC-Addressing there is a maximum jump range. However, what if the address I wanted to jump to was beyond the range? i.e. beq $s0, $s1, L1 where L1 is father away from the PC than can be supported by bne and beq. Is…
Meowmi
  • 322
  • 2
  • 11
1
vote
1 answer

Crash with all threads running SIGSEGV handler

We develop a user-space process running on Linux 3.4.11 in an embedded MIPS system. The process creates multiple (>10) threads using pthreads. The process has a SIGSEGV signal handler which, among other things, generates a log message which goes to…
YSK
  • 1,572
  • 10
  • 19
1
vote
1 answer

Switch Case in MIPS assembly

I have tried implementing a switch case in MIPS assembly but I feel like I could have made this simpler, especially with the default case. Is there anyway I can make this better? Here is my assembly code: $t1 = var $t2 = i $t3 = 4 $t4 = 1 lw…
Kreul
  • 27
  • 1
  • 7
1
vote
0 answers

MIPS Assembly Calculating memory addresses

I am learning about assembly and am doing assembly computations, particularly with MIPS instructions to calculate the changed registers and memory addresses. The initial address states are here : $t0 = 0x0000000B, $t1 = 0xFFFFFFFF, $t2 =…
Janeson00
  • 113
  • 9
1
vote
0 answers

How does the jump instruction and jump address in MIPS work?

I am a beginner trying to design an assembler for MIPS. Any help would be greatly appreciated. Suppose I have this assembly file main: lw $a0, 0($t0) begin: addi $t0, $zero, 0 # beginning addi $t1, $zero, 1 loop: slt $t2, $a0, $t1…
1
vote
1 answer

MIPS: the difference between the registers

I'm learning MIPS assembly language right now and I still don't quite understand the difference between the following registers: $at, $a, $t, $s, $v. More specifically, when should I use what
R.Bassil
  • 27
  • 1
  • 3
1
vote
1 answer

Build static library with cgo under mips64le

I’m trying to build a libtest.a with Go1.11.4 using cgo under linux/mips64le. I make a simple Go file, this is test.go code: package main import( “C” “fmt” ) func main() { } //export hello func hello(){ fmt.Println(“Hello…
wikios
  • 35
  • 1
  • 8
1
vote
0 answers

build GCC8.2.0 fails with "checking assembler for -mnan support... no"

I am trying to build cross GCC, version 8.2.0, for Mips target (not mipsel), on host Debian-SID, with mostly latest tools in it, such as gcc x86_64 8.2.0 and make 4.2.1 . loaded and unpacked these packages and versions (are they…
1
vote
1 answer

How do I copy one string to another in MIPS Assembly

Like the title states, I have one "template" string that I want to copy to another string so as to "reset" the string. Here is an example of what I'm trying to do: I have these two strings at the start: .data blank: .asciiz "-/-/-/-/-/" …
Drew Pesall
  • 179
  • 3
  • 12
1
vote
1 answer

Compiling MIPS to use branch instead of jump

Having the following very simple c program: #include #include int main() { char *buffer = (char*)malloc(20); } And Compiling it with mips-linux-gnu-gcc, it looks like the call is compiled to the following…
macro_controller
  • 1,469
  • 1
  • 14
  • 32
1
vote
0 answers

How to square a number in MIPS assembly without using mult or mul

I’m having a hard time figuring out how to square $8. I need to do this without using multiply or division. addi $8, $0, 1 #seed value addi $9, $0, 0x2010 #starting memory address addi $12, $0, 16 #so it can loop 16 times Loop: addu $8, $8, $8 #$8 =…
Rami
  • 11
  • 1
1
vote
1 answer

Beginner to MIPS, why won't it print my third prompt?

I'm trying to write a program in MARS (MIPS Assembler and Runtime Simulator) that will take two integers from the user and then either add or multiply based on what the user chooses to do. Anyways, I haven't gotten too far into the program yet,…
Brianna Drew
  • 37
  • 11
1
vote
1 answer

Mips rot encryption

So i'm trying to program the Rot47 algorithm in MIPS .data message: .asciiz "This text should probably contain something useful!" message_size:.word 51 .text main: li $t1, 0 la $t0, message loop: lb $a0, 0($t0) #load the…
SupEldrix
  • 103
  • 1
  • 8