943,958 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1998
  • Assembly RSS
May 10th, 2009
0

Checking an equality condition using BEQ in MIPS

Expand Post »
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

Assembly Syntax (Toggle Plain Text)
  1. IF a!=b

I just use

Assembly Syntax (Toggle Plain Text)
  1. else if(reltoken == neqsym) // !=
  2. {
  3. setcode(SUB, topregister-2, topregister-2, topregister-1);
  4. setcode(OR, topregister-2, 10, topregister-2);
  5. }

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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ch33s3r is offline Offline
1 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Help..!!
Next Thread in Assembly Forum Timeline: heeeeelp plz :( (assemply lang)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC