DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Assembly (http://www.daniweb.com/forums/forum125.html)
-   -   Checking an equality condition using BEQ in MIPS (http://www.daniweb.com/forums/thread191533.html)

ch33s3r May 10th, 2009 11:45 pm
Checking an equality condition using BEQ in MIPS
 
I am working on a C program that parses code from a high level language and generates MIPS code. I have a question about the logic to test for (in)equality in an IF statement. For example, my code generation for a statement like

IF a!=b

I just use

        else if(reltoken == neqsym) // !=
        {
            setcode(SUB, topregister-2, topregister-2, topregister-1);
            setcode(OR, topregister-2, 10, topregister-2);
        }

I'll explain what I'm doing here...
Basically, I use a "register stack" so topregister-1 would be the register holding the most recent value pushed onto the "stack" and topregister-2 would be the one pushed before that, etc. By subtracting these two values, I will know they are equal if the subtraction results in a 0. I then OR this value with the $zero register (which i just call 10 in my C program) If the result of the OR is a 0, then the 2 values compared are equal and the BEQ will then branch because the BEQ compares this result with the $zero register, and the if condition was false. But this test isn't the problem...My != test works but my = test does not.

Keep in mind I know that using BNE would be the "easy way" rather than using BEQ, but I am required to use BEQ to somehow do this = test. I am trying to use the same code as above, but just replacing the OR with NOR, but it's not working. When I check the hex value in the register using PCSpim (PCSpim is what I use to test my MIPS code) It shows something weird like 0xfffffe when it should be 1 or 0. I must be doing something wrong here...but I thought NOR gives you the opposite answer as OR...which is what I assume I need here because = is the opposite of !=. I hope my question makes sense.

Any help is greatly appreciated!


All times are GMT -4. The time now is 4:44 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC