Whats wrong with my 'if statement' in assembly?

Started by
10 comments, last by Emmanuel Deloget 17 years, 11 months ago
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!
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. =)
:==-_ Why don't the voices just leave me alone?! _-==:
you need an unconditional jump after you set r5 to 0.

I forget the syntax but something like

comp r3, r6beq L1set 00, r5jmp L2L1: set 01, r5L2: whatever you want to dowhat you have now is equivalent toif (r3 == r6)   r5 = 0;r5 = 1;
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
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?
You must have _some_ code after it - what happens after the if statement is complete?
hmmmm, nothing, i just want the L2: so I can skip calling L1:

Dude: CMOV
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
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?
yes, or what sort of assembly dialect is it?
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.


This topic is closed to new replies.

Advertisement