Search code examples
assembly68000easy68k

How to implement logical OR || in an if() condition in easy68k?


Suppose I have a to compare a data register and i have to compare it to equalling one of 2 numbers. how would i go about that?

I know how to do it for just comparing with one number not 2.

CMP #0, D3
BNE ELSE
REST OF THE CODE HERE

How do i compare for when I want to compare it with either 0 or some other number like 7. In c++ you would say

if(x == 0 || x == 7)
{code here}
else
{code here}

Solution

  • In assembler, there are no braced blocks, only gotos. So think about it, if x == 0 you already know you need the "then" code, but if x != 0, you have to test x == 7 to find out whether to go to the "then" code or the "else" code.

    Since C is capable of expressing this structure, I'll use that to illustrate:

    Your code

    if(x == 0 || x == 7)
        {code T here}
    else
        {code E here}
    

    is equivalent to:

        if (x == 0) goto then;
        if (x == 7) goto then;
    else: /* label is not actually needed */
        code E here
        goto after_it_all;
    then:
        code T here
    after_it_all:
        ;