• 0

[MIPS Assembly] Probably a silly question


Question

What does the 'or' instruction do? E.g. or $t0, $t0, $t1. I understand the concept of logical operators and some of the basics of assembly but I just can't figure out what this will do.

Sorry for this extremely simple question. I have researched but I can't find a decent explanation anywhere.

Thanks.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Essentially what OR does is return 0 if BOTH the bits it is comparing are 0, and 1 if EITHER the two bits being compared are 1.

In other words, if you did 1011 OR 1111 you would get 1111.

Similarily, 0001 OR 1011 would give you 1011.

It's mostly used for setting the individual bits of a word. To retrieve one, you'd basically do the opposite with AND which returns 1 if BOTH bits being compared are 1, and 0 otherwise.

Your example basically takes $t0 and changes it so that any bits that are 1 in $t1 will now also be 1 in $t0.

Link to comment
Share on other sites

  • 0
Thanks!

Just a thought, ORI (or immediate) is also used for storing a 32bit constant into a register using LUI (load upper immediate)

lui $t0, 100101...110010

ori $t0, $t0, 100101...110010

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.