Sign in to follow this  

MIPS Assembly Help

This topic is 3850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need some help using the MIPS ISA. Given a word I need to extract the four byte values that make up the word. For example, given .word 5 if I store the word in a register, $t1, I need to need perform some operation on this to get out the 4 bytes that make up the word as four byte values make up one word. My question is what instruction can I use to do this and how would I go about it. thanks.

Share this post


Link to post
Share on other sites
First, a word only contains 2 bytes, at least on x86. I have to admit I know nothing about MIPS assembly, but in x86 you can use shifts to extract the individual bytes from a register. Or you could just read individual bytes from memory (again if possible in MIPS). And the forum has a policy against homework.

Share this post


Link to post
Share on other sites
thanks for the response.

In MIPS, a word does has four bytes and not two. I guess I can use shifts to extract the bytes. I am not supposed to use the load byte instruction in MIPS so I guess shifts is an alternative. I was not trying to get my homework done through the forum. This is a small part of a project and I was stuck and just needed some help on how to go about extracting the bytes.

Share this post


Link to post
Share on other sites
Use a bitmask.

Sounds like homework to me, but I don't see any harm in helping you find reading material. I just won't give you any MIPS code, just the hint that you can do it with a single immediate-mode instruction :>

EDIT: Oh, lol, you want each of the bytes. Hurr, that'll take more than one instruction :>

Share this post


Link to post
Share on other sites
Thanks, I got how to extract the 4 bytes from a word using the srl and and instructions.

.data
start: .word 1568784958

.text
main: la $t1, start
lw $t2, 0($t1)
andi $t4, $t2, 255
srl $t2, $t2, 8
andi $t3, $t2, 255
srl $t2, $t2, 8
andi $t5, $t2, 255
srl $t2, $t2, 8

My final question is how would I go about packing 4 bytes into a word? thanks.

Share this post


Link to post
Share on other sites

This topic is 3850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this