banner



How To Set Bits To 1 In A Register In Mips

You are using an out of date browser. Information technology may non display this or other websites correctly.
You should upgrade or apply an alternative browser.
  • Forums
  • Homework Help
  • Engineering and Comp Sci Homework Help

Set bits xviii, 19, 20, 21 to one ( Mips)

  • Thread starter basketball853
  • Start date

Homework Statement

Set bits 18, 19, 20, and 21 to 1 in annals $v0. $v0's other $.25 should not change. This tin be washed in 2 MIPS instructions. Do not employ whatever pseudo-instructions or load any data from retentiveness. You may use whatsoever registers that you wish.

Homework Equations

Here is more than on the idea: if $v0 did look similar this:

0b0000 0000 0000 0000 0000 0000 0000 0000 = 0x00000000
and then afterward, it should look like (counting from chip 0):
0b0000 0000 0011 1100 0000 0000 0000 0000 = 0x003C0000

Basically, just observe that bits eighteen through 21 have been turned "on."

The Attempt at a Solution

I am having problem fifty-fifty coming to a possible solution in two steps... i know that the target is register $v0 and i take to turn 18, 19, 20, 21 into 1111 ( or F in hex) but i do not know where to showtime... Also i know that i maybe able to use the slt opcode ? which is set up if less than to 1

whatsoever thoughts ?

Answers and Replies

Would peradventure the ORI pedagogy exist of utilise?
how could i implement that though? good suggestion ... like an ex..
First, you lui into a temp register for example

lui $t0, 0000 0000 0011 1100

then, you or that with v0.

or $v0, $v0, $t0

Like shooting fish in a barrel enough :)

how could i implement that though? good proffer ... like an ex..
Well, let'southward say you've got this binary number:

1001 1101

And at present you lot want to set these $.25 to 1:

0011 0000

OR them together, you lot go:

1011 1101

OR is pretty much how bits are set, in general. While I'thou on the topic, in instance you don't know, AND works equally a bit mask. ANDing something with a 1 leaves it unchanged, simply ANDing it with 0 sets information technology to 0. Knowing those uses of AND and OR are very important, so I'k just mentioning it in case you lot didn't know or forgot.

Yous've been told about the register containing the number in which you want to set the bits. The ORI education has this syntax:

ori $t, $s, imm

The source ($southward) you lot want is $v0, as is the target ($t). The immediate role should be just the number with but the bits you wish to brand into 1s set to ane.

P.S. Not sure what y'all mean by "like an ex"

You lot couldn't but but or it, because that would simply permit you to alter the lower 16 bits. By using the lui into another temp, information technology allows yous to manipulate $.25 16-31.

as well: I think by "similar an ex" he meant "like an example."

Yous couldn't simply only or it, considering that would only permit you to change the lower 16 bits. Past using the lui into some other temp, it allows you lot to dispense bits fifteen-31.
I totally missed that. Thanks, squeamish catch.
Thank You Guys for all of the assist! i run into how simple information technology is now... i totally forgot about lui lol it slipped correct passed me, and i definitely didn't know about masking! i will read up on it more!!

Thank you SOOOOOO SOOOOO SOOOOO SOOOO MUCH!!!!!!

Oh!! and guys how could i possibly get nearly having that aforementioned annals $v0, set bits 31 and 30 to 0 and 1 respectively. Additionally, set bits four and five to 1 and 0 respectively.

In six steps ? should i lui once again to manipulate sixteen-31?

Hahahah... This is quite ironic, I had the verbal same homework questions...
Well i know that before $v0 = 0b1000 0000 0000 0000 0000 0000 0010 1111
and subsequently $v0 = 0b0100 0000 0000 0000 0000 0000 0001 1111

so would i just lui for the 32 bits and and then ori ? for the balance

No, information technology's a lot different than the first.

lui allows you to modify the upper xvi $.25, but makes the lower 16 $.25 0.

hmmm okay... ill attempt to effigy it out
Basketball,
You must accept the same homework as me. Non simply do I have the aforementioned two issues, merely information technology'southward due today. I'm still trying to figure out the terminal one.
Oh!! and guys how could i possibly go about having that same register $v0, ready bits 31 and xxx to 0 and i respectively. Additionally, set up bits 4 and 5 to 1 and 0 respectively.

In half-dozen steps ? should i lui again to manipulate xvi-31?


The usual terminology is that you are setting bits 30 and 4, and clearing bits 5 and 31. Setting a fleck means putting a 1 at that place. Immigration a chip means putting a 0 there.

To ready a bit, OR the register with an immediate value with a 1 in the correct position. To clear a flake, AND the register with an firsthand value with a 0 in the position.

I'll leave you to work out the details of working with the lower and upper 16 bits.

ok so in order to acomplish this i just wrote out 32 $.25...
0000 0000 0000 0000 0000 0000 0000 0000
and do i count from right to left with 0 ? soo that being
0100 0000 0000 0000 0000 0000 0001 0000
right?
if this is the example then tin can't i practise:
lui $t1, 0x4000
ori $t1, 0x0010

and thats information technology ?

it seems piece of cake enough? but i know thats incorrect considering it asks for 6 steps

if this is the case and so can't i do:
lui $t1, 0x4000
ori $t1, 0x0010

and thats information technology ?

information technology seems easy enough? merely i know thats incorrect because it asks for 6 steps


Nope, not quite that simple. Also, the format of your ORI instruction is wrong. Ok, yous demand to utilize an OR type performance to set $.25 to 1, correct? And you need an AND type instruction to set bits to 0.

For the high role, you'll need 2 instructions for the ORing and 2 instructions for the ANDing since y'all must use LUI, so that'south 4 instructions. Then you need to practice then on the lower 16 $.25, which requires ane pedagogy for ORing and 1 for ANDing, since you lot don't need to LUI anything, only can use firsthand manner. That's vi instructions.

You lot already know how to ready bits to i, I believe. And so how would you go about setting bits to 0 with AND type instructions?

Related Threads on Prepare bits eighteen, 19, 20, 21 to one ( Mips)

  • Terminal Postal service
Borek
  • Last Post
Lord Doppler
  • Last Post
  • Last Post
Mark44
  • Concluding Post
Mark44
  • Last Post
  • Last Mail service
Mark44
  • Last Postal service
rcgldr
  • Last Post
Mark44
  • Final Post
rcgldr
  • Forums
  • Homework Help
  • Applied science and Comp Sci Homework Aid

Source: https://www.physicsforums.com/threads/set-bits-18-19-20-21-to-1-mips.468996/

Posted by: masontived1986.blogspot.com

0 Response to "How To Set Bits To 1 In A Register In Mips"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel