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

I'm trying to run qtSPIM simulator using c code but it always cause error

I made assembly code from c code using gcc mips compiler but it does not work in SPIM simulator. How can I success to run SPIM? Or is there any other method to obtain assembly code fit to SPIM?
chris
  • 11
  • 1
1
vote
0 answers

Calculating Cache miss rate - set associative

Piece of MIPS code: .data first-node : .word 10,next-node next-node: ....... .text la $s0,first-node move $s1,$zero loop: la $t0,0($s0) add $s1,$s1,$t0 lw $s0,4($s0) bne $s0,$zero,loop we got list of 4096 nodes, Cache one-way 16 set Block size: 128…
Kukuriku
  • 13
  • 5
1
vote
2 answers

'hanoi towers' recursive solution using MIPS

I am new to asking questions on stack overflow, and even newer to MIPS. I tried implement the following recursive solution to the 'hanoi towers' problem (taken from here) using MIPS. I think my failure in doing so lies behind the fact that I don't…
Marko Klei
  • 11
  • 1
  • 2
1
vote
0 answers

Is there are way in MIPS to do the logical AND operation using hexadecimal?

For example you have the code: addi $s1, $zero, 0x1234 andi $t0, $s1, 0x0f0f You can figure out what goes in $t0 by converting 0x1234 (the value inside $s1) and 0x0f0f into binary code and doing the AND operation from the two numbers. However, is…
1
vote
0 answers

Why does strace believe this memory is uninitialized when attaching to a process?

I have an extremely simple program that does nothing more than call recvfrom() in a loop. According to its manpage, one of the arguments is a pointer to the length of the address. This address is initialized in the .data section to the integer value…
forest
  • 206
  • 4
  • 15
1
vote
1 answer

Printing from a declared array in MIPS

So I'm making something that looks like this for(i=0; i<10; i++){ print i; } but in MIPS, and i'm having trouble understanding how i'm supposed to increment the index location. Here is what I have so far .data a: .word 3, 2, 1, 8,…
Lexie Anne
  • 71
  • 1
  • 1
  • 7
1
vote
0 answers

Enable keyboard interrupts for Qemu emulating MIPS Malta

I am writing a kernel for the MIPS Malta board using QEMU and I am having difficulties getting keyboard interrupts to work. I've set the keyboard and display interrupt bits (bits 11 and 12) in the coprocessor 0 STATUS register and enabled interrupts…
1
vote
1 answer

MIPS: Editing files

I can't find a source to learn how to edit files on MIPS. So far I have a code that write on a file, but it just overwrite the file and not actually just modify some parts. What I wanted to is for example, the text file has: Happy 20th Birthday! and…
MonkeyD
  • 15
  • 4
1
vote
0 answers

Can some one help me out with frame storing? (Assembly Mips)

I have a simple calculator program in MIPS assembly, but for some reason it is just returning zeros. Can someone help me out? I think I may have messed up the frame storing although I am not sure. Also, I am not sure if I am using the beq command…
C Sand
  • 11
  • 1
1
vote
0 answers

Why did these lines of Assembly crash QtSpim?

This is a block of code I had to describe a subprogram. QtSpim crashed when I opened the file. I didn't get a chance to run it. ########################################################### # Read Structure # # # # 1. Iterate through the array and…
1
vote
2 answers

How are the maximum single jump range of MIPS branch instructions calculated?

I am studying computer architecture (MIPS architecture) and read the following statements: 1.Branch instructions have a 16 bit signed word offset field that allows a branch to an address + or -128kBytes (+0x1FFFC TO -0X20000) from the current…
bubuStar
  • 563
  • 1
  • 3
  • 8
1
vote
1 answer

Incorrect exception adress for MIPS Malta in QEMU?

I'm writing a small kernel for MIPS Malta on a Linux machine, Ubuntu 18.04, and emulating the host using QEMU. When trying to implement exception handling however, I'm confused by the memory mapping provided by Qemu. Most of the documentation online…
1
vote
0 answers

MIPS Program: Number of Instructions

How do I count the total number of instructions executed in the following MIPS program? ADDI R1, R0, #1 SW R1, 2000 (R0) LOOP: LW R1, 2000 (R0) MULT R2, R1, #4 ADDI R3,R2, #5000 LW R4, 0 (R3) LW R5, 1500 (R0) …
1
vote
0 answers

Trouble translating to MIPS

I need help understanding MIPS for an assignment. I am trying to translate this pseudocode S = “Jane Doe” //array S that stores your name as a string of bytes of ASCII characters //S[0]=’J’=0x4A; S[1]=’a’=0x61;…
sbowde4
  • 767
  • 1
  • 4
  • 23
1
vote
1 answer

mips string copy: error in spim

Q1. In my class ppt, that codes are written, but the MIPS code does not work in SPIM. How can I revise the MIPS code? Q2. Assume that address of x and y are 100 and 200, respectively, and i = 10 and sp = 500. How can I revise MIPS code with that…
1 2 3
99
100