MIPS Subtraction: How to subtract two numbers with Examples

To understand subtraction in MIPS assembly language, you must have the understanding of following topics in MIPS assembly language:

As now you have the basic understanding of the above topics you can learn subtracting two numbers in MIPS assembly language.

MIPS Subtraction Examples

we will discuss two examples, the first in which we will take values from the user and in the second example we will initialize registers with the value of our own choice.

Q: Write a program in MIPS that takes two values from the user and perform subtraction between then also print the subtraction result.

PROGRAM

OUTPUT

EXPLANATION:

In the above MIPS subtraction example, we first ask the user to input the value by printing msg1 and then ask to enter another value by printing msg 2. Then we moved these values to register $t1 and $t2.
After moving the values to the registers, we used the SUB OPCODE to perform subtraction. After then we store the final result in register $a0 to print it.


Q: Write a program in MIPS, take two values of your choice and perform subtraction between then also print the subtraction result.

PROGRAM

OUTPUT

EXPLANATION:

In the above program, we directly initialized two registers with integer values. We use SUB opcode to perform subtraction process and finally print the result.


That was all about MIPS subtraction process, comment to show me that you are alive!

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.