I have a block of MIPS code that implements a pseudo-instruction operating on the values from two registers. The problem is i am having trouble undertanding what it does. The code is:

srl $s1, $s1, 1
sll $t0, $s0, 31
srl $s0, $s0, 1
or $s1, $s1, $t0


The 4 instructions accomplish new $s0 $s1.

If any one can help me out with what it does, that would be great.

Presumably s0 and s1 are the arguments to your function...

Look through and try to see what is happening to each register. I find it convenient to get out the crayons and construction paper and make little boxes with the values of each register in it (seriously).

The result is that register s0 is logically right-shifted by one bit,
and register s1 is also right-shifted by one bit but the MSB gets the bit shifted out of register s0.

In other words, you are treating s0 and s1 as if they were a single, double-sized register and logically shifting the whole thing right by one bit.

This won't make a bit of sense until you get out the paper and colored pencils and draw it.

Hope this helps.

Oh yeah, you should invest in a book called "A Programmer's View of Computer Architecture" by Goodman and Miller.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.