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

MIPS Input validation - how to read ints and text

I've been learning a bit about MIPS and I'm required to write a Factorial program that takes in input and prints out nth Factorial. Positive integers are not a problem, and their spec requires me to print 1 for negative input which is fine since…
Calahan
  • 35
  • 6
1
vote
0 answers

how to convert a decimal base integer into base 4 integer in MIPS?

hey friends im new to mips and im trying to convert numbers from a linked list into base 4 and print them out but i dont really know how to do that i have heared about a way with dividing the numbers by 4 and pushing the remainder of each number to…
dor
  • 25
  • 1
  • 7
1
vote
0 answers

MIPS:representing a mips assembly in machine code

BSD [nextCH is 0x400100] nextCh: lb $t0,-3($t2) beq $t0,$zero,strEnd add $t9,$t9,$t0 addi $t2,$t2,-12 j nextCh strEnd: I can't figure out what to do with strEnd. How can I represent it in decimal?
Aby_g
  • 53
  • 1
  • 7
1
vote
1 answer

MIPS Manipulating array stored in data

I can't seem to visualize how this works. I'm trying to translate this simple assignment from C to mips: #define ARRAYSIZE 16 int intarray[]={1, 5, -3, 6, 12, 21, 18, 44, 32, 9, 23, 10, 11, 99, 100, 24}; intarray[little] =…
Voxorin
  • 89
  • 10
1
vote
0 answers

compilation for multiple MIPS platforms

I have multiple MIPS platforms with different CPUs and different kernel and uclibc versions I'm want to compile 'Hello World' program with single toolchain that will run on all of the devices. I'm building the toolchain using crosstool-ng with the…
1
vote
1 answer

MIPS Assembler Read String overrides Print String

.text la $t5, prompt la $t6, prompt_char la $t7, prompt_loop loop: la $t4, 0 #count askForString: la $a0, prompt li $v0, 4 syscall li $v0,8 li $a1, 5 #text einlesen syscall j quit quit: la $a0, ($t7) li $v0, 4 #info syscall li $a1, 5 #text…
beceras
  • 11
  • 1
1
vote
1 answer

4x4 matrix multiplication: Exception 4: Unaligned Address in inst/data fetch: 0x100100bb

I'm trying to to do a 4x4 Matrix multiplication using Assembly in MIPS simulator (QtMips). QtMips gives me Exception 4: Unaligned Address in inst/data fetch: 0x100100bb This is where I get the error when I single step. [00400070] c52b0000 lwc1…
Leonard
  • 2,978
  • 6
  • 21
  • 42
1
vote
1 answer

Running Android on Mips Architecture

If I have a set top box(Mips arch) with the source code(with a modified Linux kernel) which makes it run, and now I want to run Android on it, how do I proceed? Updating my kernel source by comparing it with the common Android kernel tree should be…
Sid Ramadoss
  • 521
  • 2
  • 6
  • 13
1
vote
0 answers

Memory address out of bounds error in MIPS

I used the following code to print a hello world message but when run an error saying 'Memory address out of bounds' pops up. Why does this happen? .text main: la $v0, hello_msg li $v0, 4 syscall #Data storage .data hello_msg : .asciiz "Hello…
she_grab
  • 77
  • 9
1
vote
1 answer

MIPS: use label in base-offset addressing

I'm trying to use a label as the offset in base-offset addressing mode, for accessing a global variable in a shellcode-like environment. The base address of the code and data is stored in $s7, and I'm trying to do this: # global variable @ offset 20…
jclehner
  • 1,440
  • 10
  • 18
1
vote
1 answer

Copying elements from one array to another in MIPS assembly

I'm new at MIPS and have been trying to copy elements from one array to another. I'm unsure about how to go about this. It doesn't really matter what size the array is but lets just say for the sake of doing it that its size 10. I am little weak…
Brian
  • 11
  • 1
  • 2
1
vote
0 answers

webrtc mips build: why rtc_executable build generate ELF 32-bit LSB share object instead of ELF 32-bit LSB executable

I tried to cross compile webrtc for mipsel: 1)gn gen out/mips --args=target_os=”linux” target_cpu=”mipesel” 2)ninja -C out/mips Build succeeded, and I wan to run some example demo codes such as example/peerconnection/server, the artifact was…
1
vote
1 answer

QtSpim Assembler: Error on stack operation with double

i'm writing a program for class. It takes x and epsilon from the console and should retrieve an sin(x) approximation. When i run it in QtSpim i get the error: Unknown instruction type: 0 The error occurs here: floatsin: addi $sp, $sp, -64 …
radiosonic
  • 35
  • 6
1
vote
1 answer

How to account for hidden bit in mantissa? MIPS code IEEE-754

This is my code for printing just the mantissa of a floating point. The value stored in $t1 is the value 0xBEDCFFFF, which has a mantissa of 10111001111111111111111. My code prints this without the one in the beginning. How do I write the clause to…
James
  • 13
  • 5
1
vote
1 answer

Does register #30 ($fp) have anything to do with the jal function in MIPS?

"jal Rout is the instruction which is executed by the MIPS processor and is located in the address 0x00400100. The label Rout is points to a subroutine which is located in the address 0x00555500. What will be the value of register #30 ($fp, frame…
Zap
  • 325
  • 1
  • 6
  • 23