# Short MIPS Program

1. Dec 5, 2011

4. Dec 6, 2011

### chiro

Hey johnnyrocket and welcome to the forums.

A signed integer will have one of its bits set to 1 (usually the most significant bit), so you should be able to do a bitwise AND which will return 0 if positive or a non-zero number if negative.

5. Dec 6, 2011

That will take an extra instruction. So will an arithmetic shift right of 15 bits that will produce a 0 for positive or -1 for a negative number. There's are a couple of MIPS instructions that will do what he needs in a single instruction once $a0 has the value to be tested. This is more of a search exercise than some clever usage of math oriented instructions. 6. Dec 6, 2011 ### johnnyrocket thanks for the reply. If I use 1 instruction to put the immediate value into the register, and the 2nd value to shift, that should do it right? li$a, value
srl $v,$a,31

7. Dec 6, 2011

### rcgldr

update - I was thinking of chiro's post, not yours. The logical right shift will work.

Last edited: Dec 7, 2011
8. Dec 6, 2011

### johnnyrocket

if the \$a0 register has a 32 bit value in it, how will shifting it right 31 bits produce anything other than a 1 or 0 (the 1st bit)?

If I have 10000000000000000000000000000000 and I shift right 31 bits im left with a 1(with 31 0's in front of it to make it 32 bits) right?

9. Dec 7, 2011

### chiro

What about a test instruction? In normal Intel assembly there is a test function that tests whether something is zero or not by performing an AND operation and using the result.

10. Dec 7, 2011

### rcgldr

I was thinking of chiro's post not yours. The logical right shift will work.

You also could have used SLT (set on less than) with an immediate value of 0, but the logical right shift is a more generic solution since many processors don't have an instruction like SLT.

Last edited: Dec 7, 2011