MIPS Addition: How to Add Two Numbers Example

In this section, we will discuss how to add two number in MIPS instruction set(MIPS Addition). For addition MIPS we use R format in which an opcode ADD is used. To understand MIPS addition you must understand the following topics:

After the understanding of above topics proceed towards MIPS addition examples:

MIPS Addition Examples

We will discuss two types of examples here:

Q: Write a MIPS program to Take two values from the user, Add these values and print the output.

PROGRAM:

OUTPUT:

Explanation

In the above program we use three registers $t1, $t2 and $t3. In register $t1 and $t2 we saved the values taken from the user and in register $t3 we saved the result of addition. We use Add Opcode for addition and used arithmetic and logical format.


Let’s take another example of MIPS Addition:

Q: Write a MIPS program to Take two values of your choice, Add these values and print the output.

PROGRAM:

OUTPUT

Explanation

In the above program, we initialize $t0 and $t1 register with values 5. We didn’t used labels to input values from the user. We used only one label “msg” to display the results.

 

Nauman Rehmat
 

Nauman Rehmat is the owner of Assembly Language Tuts.He is interested in Programming and SEO. He is also pursuing a degree in Computer Software Engineering from Comsats.