Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Whats wrong with my 'if statement' in assembly?

This topic is 4439 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

Hi, i'm doing some assembly and I'm trying to do an if statement, if cc == 0 set reg5 to 1 else set reg5 to 0
comp r3, r6     // 
beq L1          //if cc == 0 goto L1
set 00, r5      //else if cc != 0, set r5 to 0
//problem:keeps going to L1 from here
L1: set 01, r5  //set r5 to 1

The problem is 'if cc !=0' it sets 'r5' to 0 fine, but continues to 'L1', and sets it to 1 aswell. What am I doing wrong? thx!

Share this post


Link to post
Share on other sites
Advertisement
Maybe you should handle a '!=' (or "if (r3 != r6)") and send it to L2, if it reaches that point. I'm no expert in Assembly, but that's my guess. =)

Share this post


Link to post
Share on other sites
you need an unconditional jump after you set r5 to 0.

I forget the syntax but something like


comp r3, r6
beq L1
set 00, r5
jmp L2
L1: set 01, r5
L2: whatever you want to do

what you have now is equivalent to

if (r3 == r6)
r5 = 0;
r5 = 1;

Share this post


Link to post
Share on other sites
Ah right I see,

With the
L2:

I want it to goto that position, but I don't want to put any code next to it, but I can't compile it unless I do.

What should I do?

Share this post


Link to post
Share on other sites
Quote:
Original post by johnnyBravo
hmmmm, nothing, i just want the L2: so I can skip calling L1:


Yes, but what happens _after_ that? Something must.

Quote:
I can't compile it unless I do


What error message do you get?

Quote:
Dude: CMOV


Except this does not look like x86 assembly.

Which architecture is it, BTW?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yes, or what sort of assembly dialect is it?

Share this post


Link to post
Share on other sites
I'm not really sure which dialect it is, I'm using 'Yet Another Assembly Simulator' written by someone at Macquarie Uni, our lecturer said its x86.

the error is some numbers 'opcode not recognized', over and over.

I ended up just storing it:
L2: store r5, 01

Which wasn't part of the question guidelines.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!