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

Converting lower case from file to upper case to another file

I'm a student currently learning mips and I have a a question as followes: Take all the lower-case letters from a file, convert them into upper-case letters and print them in a different file. I tried opening the first file, called "Alice", this is…
Noam Hadad
  • 11
  • 3
1
vote
0 answers

How to fix bad address error in MIPS assembly

I am very new to MIPs programming and have been struggling alone to solve to problem. I am in need of help from people of expertise, to help me through the way. I am trying to build a program that takes in multiple integer inputs from the console…
jamesdean
  • 21
  • 5
1
vote
2 answers

Is there an efficient way in MIPS to store floating point numbers in a dynamically allocated array?

I'm trying to store a list of floating point numbers in a dynamic array using MIPS. The program prompts the user for the number of floats to enter, and then loops while receiving the input. With integers I know how to do this, but I am having a hard…
zach
  • 61
  • 1
  • 6
1
vote
1 answer

How can I return an array from a MIPS procedure?

What is the standard way of returning an array of addresses or values from a MIPS procedure? For instance, suppose, I want to read a sentence and want to return the words found in that sentence. Or, suppose, I want to return the positions of the 1st…
user366312
  • 16,949
  • 65
  • 235
  • 452
1
vote
1 answer

MIPS - Help initializing array

I am trying to initialize memory array to values 1, 2, 3.. 10. Though I am having a bit of trouble. Here is my work so far: .data myarray: .space 10 .text la $t3, myarray # Load the address of myarray addi $t2, $zero, 1 # Initialize the first…
1
vote
1 answer

How to multiply two numbers in MIPS which gives product that is larger than 32bits?

Actually, my task is to multiply two 32bits number in MIPS which then generate the output of 64bits. Least significant 32bits are to be saved in 'lo' register and the remaining in 'hi' register to my understanding. When I multiply 100000 and 200000…
Abdul Ahad
  • 51
  • 5
1
vote
1 answer

How can I implement if(x >= '0' && x <= '9') range checks like isdigit in MIPS?

I have written the following function to check whether a character is a digit or not: # IsDigit - tests a if a character a digit or not # arguments: # $a0 = character byte # return value: # $v0 = 1 - digit # 0 - not a…
user366312
  • 16,949
  • 65
  • 235
  • 452
1
vote
1 answer

Multiplication in MIPS by shifting and adding, without mult

I have the following code, but I keep receiving an Arithmetic Overflow error. The problem that I am trying to solve is multiplying two 31-bit numbers together and storing the results in $t2 $t3 and printing out the correct result. It seems that I…
rdopler
  • 17
  • 2
  • 7
1
vote
1 answer

Is the difference between programming model wrt Program Counter and Stack Pointer in case of Assembly?

Processor model I ● Registers  PC – Program Counter  Single data register (accumulator) without name  We will use symbol A to describe operations on this register ● Stack with an unspecified implementation ● Data specified…
user366312
  • 16,949
  • 65
  • 235
  • 452
1
vote
1 answer

Boost.asio compilation problem: undefined reference to `__sync_add_and_fetch_8

Hey guys, This could be a noob question, but I really can't find any useful solution through Google. I'm testing a hello world with boost.asio, the program is quite simple: #include #include #include…
Tony
  • 453
  • 4
  • 7
  • 16
1
vote
3 answers

How do I calculate clock cycles on mips assembly programming?

I've searched up everywhere, and ive gathered pipelines or something. I've checked other programs and it seems like theres a single-cycle & multicycle: Clock cycles of Single-cycle and multi-cycle MIPS How do I tell the difference for what cycle.…
Jordles
  • 45
  • 2
  • 9
1
vote
0 answers

MIPS - how to convert a float input into integer without using conversion instructions ,and use either shift or rotate only?

li $v0, 4 # system call code for Print String la $a0, prompt # load address of prompt into $a0 syscall # print the prompt message li $v0, 6 # system call code for Read float syscall # reads the value of N…
Kevin
  • 11
  • 2
1
vote
1 answer

Is my understanding of lw instruction in MIPS correct?

I am just starting to understand MIPS, and the particular instruction "lw" confuses me. From the thread, Understanding how `lw` and `sw` actually work in a MIPS program, this is what I have gathered: If, say, we have: lw a, 4(b) // a and b are…
Tina
  • 179
  • 1
  • 3
  • 13
1
vote
3 answers

golang binary not running on mips

I'm using Go 1.11.4 on Windows 10 and I want to compile code for a MIPS 74Kc processor (Qualcomm Atheros QCA9558) running Linux. I compile with: GOOS=linux GOARCH=mips go build Get an executable, upload and run it and get: Illegal instruction Try…
User1
  • 39,458
  • 69
  • 187
  • 265
1
vote
1 answer

How is this gcc-generated strlen() mips loop not off-by-one?

Here is the source code for a very basic strlen() implementation. #include #include extern uintptr_t lx_syscall3(uintptr_t a, uintptr_t b, uintptr_t c, uintptr_t nr); static void lx_sys_exit(uintptr_t code) { …
Hypertable
  • 123
  • 8