How To Set Bits To 1 In A Register In Mips
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
lui $t0, 0000 0000 0011 1100
then, you or that with v0.
or $v0, $v0, $t0
Like shooting fish in a barrel enough :)
Well, let'southward say you've got this binary number:how could i implement that though? good proffer ... like an ex..
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"
as well: I think by "similar an ex" he meant "like an example."
I totally missed that. Thanks, squeamish catch.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.
Thank you SOOOOOO SOOOOO SOOOOO SOOOO MUCH!!!!!!
In six steps ? should i lui once again to manipulate sixteen-31?
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
lui allows you to modify the upper xvi $.25, but makes the lower 16 $.25 0.
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.
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, 0x0010and 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
- Last Post
- Last Post
- Last Post
- Concluding Post
- Last Post
- Last Mail service
- Last Postal service
- Last Post
- Final Post
- 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