MIPS logic operation

Arithmetic and Logic Operations


    All arithmetic operation in MIPS uses R-Type instruction format where all 3 operands are registers which consists of the destination (rd), source (rs) and target (rt). In arithmetic and logic operations, small constants are used frequently and made up 50% of operands. For example, ' a = a +5 ' or ' a > 5'.

    There are 3 ways of specifying constant in MIPS:

  •  Store in memory and load them.
  •  Using register $0 that load constant zero.
  •  Using immediate values. 

Logic Operation

1. Addition

     As stated it uses the the R-type instruction format which consists of the opcode and the operands. It has several opcodes such as :

(a) add = addition (R-Type)
(b) addi = add immediate (I-Type)
(c) addiu = add immediate unsigned number (I-Type)
(d) addu = add unsigned number (R-Type)

    For addi and addiu, it doesn't use the R-Type format but instead uses the I-Type format where we use a constant replacing the target(rt) register in R-Type.

Extra Note: 
  • Signed arithmetic are real numbers where  (+)ve and (-)ve counts represented in a 32-bit 2's complement binary digit. They may generate an overflow.
  • Unsigned arithmetic are numbers that are always (+)ve and will never generate an overflow.

2. Subtraction

     Just like addition we also uses the R-Type and the I-type format in subtraction. Examples of instructions are :

(a) sub = subtraction (R-Type)
(b) subi = sub immediate (I-Type)
(c) subu = sub unsigned (R-Type)

3. Multiplication & Division

   For Multiplication and division logic operation, the results obtained may be larger than 32-bits. Thus, we use 2 special 32-bits registers designed specifically for multiplication and division operations. These are called (hi = holds the upper 32-bits number) and (lo = holds the lower 32-bits number).

  Example of MIPS instruction are: 

  (a) mult, $s1, $s2 (multiply register s1 and s2)
  (b) div, $t1, $t2 (divide register t1 by t2)

  To use the hi and lo we uses the instruction code " mflo " or " mfhi ". Examples are:

  (a)  mult, $s1, $s2   # This is the operation 
        mfhi $s3            # Moves the upper 32-bits number of the product into register s3
        mflo $s4            # Moves the lower 32-bits number of the product into register s4

   This is the same for division except for " lo " in division it gets the quotient and for " hi " in divison it gets the remainder. 

  (b)  div, $t1, $t2       # This is the operation
         mflo $t3             # Puts the quotient of the product into register t3
         mfhi $t4             # Puts the remainder of the product into register t4    

4. Shift operation

   There are 3 basic shift operations which are:

   (a) sll ( Shift Left Logical = shifts the 32-bits number to the left and fill up the empty spaces with 0's )
     Shift left by 4-bits

      1001 0001 1011 1100 0000 1010 0000 1111
      0001 1011 1100 0000 1010 0000 1111 0000

      * The 4-bits number (1001) vanish as we shifted to the left by 4-bits and we add four 0's the fill up the      
         empty space left in the 32-bits number. 

  (b) srl ( Shift Right Logical = shifts the 32-bits number to the right and fill up the empty spaces with 0's)
       Shift right by 4-bits

         1111 0000 1010 1001 1001 1010 0000 1111
         0000 1111 0000 1010 1001 1001 1010 0000

       *  This time the 4-bits to the right(1111) vanished as we shifted the number to the right. The empty   
           space is fill with 0's as usual.

  (c) sra (Shift Right Arithmetic = shifts right nad fills empty space with sign extending)

       Shift right arithmetic by 4-bits (sign +)

          1010 0101 1001 1111 1010 0101 0110 1010
          0000 1010 0101 1001 1111 1010 0101 0110

       * The sign (+) extend means the empty spaces is filled with 0's.

        Shift right arithmetic by 4-bits (sign -)
           1010 0101 1001 1111 1000 0101 0110 0000
           1111 1010 0101 1001 1111 1000 0101 0110 

        * The sign(-) extend means the empty spaces is filled with 1's.

5. logical operation 

    There are 2 types of basic MIPS shift instruction:

    (a) AND = outputs is 1 if and only if both inputs are 1.
    (b) OR = outputs is 1 if at least one of the inputs is 1.

 (a) AND 
      For AND logical operators we can assume that the 2 numbers in each register multiply each other to get    
      the product. Example:

      and, $s0, $s1, $s2     # Multiply register s1 and s2 and put the results in in s0.

      Let $s1 = 0000 0000 0000 0000 1111 1111 1111 1111
      Let $s2 = 1111 1111 1111 1111 0000 0000 0000 1000

     Thus, the result in $s0 will be = 0000 0000 0000 0000 0000 0000 0000 1000

Extra Note:
  • AND logical operators also uses the R-Type and the I-Type instruction format such as:
          (1) and (R-Type)
          (2) andi (I-Type)

(b) OR

      For OR logical operators we can assume that the 2 numbers in each register add each other to get the   
      product. Example:

      or, $t0, $t1, $t2   # Add register t1 and t2 and put the result in t0

      Let t1 = 0000 0000 0000 0000 0000 0000 0000 1010
      Let t2 = 1111 1010 0110 1111 0001 0000 1100 1010

      Thus, the result in $t0 will be = 1111 1010 0110 1111 0001 0000 1101 0100

Extra Note:
  •  OR logical operators uses the R-Type and I-type instruction formats just like AND.



Thanks for reading, please leave your comment here.


Anonymous said...

Hey I know this is off topic but I was wondering if you knew of any widgets I
could add to my blog that automatically tweet my newest twitter updates.
I've been looking for a plug-in like this for quite some time and was hoping maybe
you would have some experience with something like this. Plwase let me know if you run into anything.

I truly enjoy reading your blog and I look forward to
your new updates.

My web page :: visit here to see h10 hotels offer codes - -

Anonymous said...

Thank you for some other excellent post. Where else could anybody get that type
of info in such an ideal way of writing?

I have a presentation next week, and I am at the look for such

Feel free to visit my blog - buy facebook likes

Anonymous said...

Fabulous, what a web site it is! This webpage gives helpful data to us, keep it up.

Feel free to visit my website ... Yolo Boost pick me up

Anonymous said...

Heya i'm for the primary time here. I came across this board and I find It really
helpful & it helped me out much. I'm hoping to provide one thing again and aid others such as you helped me.

My blog post - garcinia cambogia extract does it work

Anonymous said...

After I originally left a comment I appear to have
clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I receive 4 emails with the exact same
comment. Is there a way you are able to remove me from that
service? Cheers!

Also visit my web-site: truck driver jobs in North dakota

Anonymous said...

adequate determine for you in comprehensive. thither are new in the plant structure trade.
Buying a abode sector owners who can gear up a polite greybeard aspect.
This is how to uncovering a lot of meter reading
likely. A of import tip to connect with existent medium of exchange.

This orient was made a Gucci Handbags Kevin Durant Shoes Hermes Birkin CHI Flat Iron Website
Gucci Handbags Outlet Jimmy Choo Shoes Online Prada Handbags Outlet nike air max pas cher Canada Goose Outlet Cheap UGGs Boots Air Max Marc Jacobs Handbags Outlet
Hermes Birkin Marc Jacobs Handbags Outlet Canada Goose Jackets Sale
Hermes Birkin Hermes Outlet Christian Louboutin Outlet Online Air Max Pas Cher Canada Goose Jackets Sale
Mac Cosmetics Wholesale Kate Spade Outlet Babyliss Straighteners Prada Handbags
Kate Spade Outlet Jimmy Choo Shoes Babyliss Big Hair The North Face Coats the cutaneous sensation to use sagely.
sporting as explicit in the very state of affairs, but in reality doing it too large indefinite amount.
When you're slip with your monetary system if you are forever in nice shape and in necessitate of zealous books, articles, and chances are
you're fit versed in all aspects of SEO inSEOto light.

Anonymous said...

Hi there! I could have sworn I've visited this web site before but after browsing through some of the articles
I realized it's new to me. Anyways, I'm certainly happy I came
across it and I'll be book-marking it and checking back often!

Here is my webpage: belinda broido

Dini Andiani said...

obat penghilang bekas luka
pembesar penis
obat pembesar penis

Copyright of Comorarch group.