Question

I'm writing a program for 68k processor in ASM.

And I need to make something like that

if (D0 > D1) {
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
} else {
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
}

But the problem is that it only allows me to either branch to some pointer or continue execution.

Like so:

CMP.L   D0,D1       ; compare
BNE AGAIN       ; move to a pointer

What is the easiest way to make such construction as above?

Était-ce utile?

La solution

you can try something like this:

if (D0>D1) {
    //do_some_stuff
} else {
    //do_some_other_stuff
}

Should be:

CMP.L   D0,D1       ; compare
BGT AGAIN  
//do_some_other_stuff
BR DONE
AGAIN:
//do_some_stuff
DONE:

Read more about conditional branching

Autres conseils

The control structure that is best suited for this scenario is BGT.

BGT (Branch on greater than) will branch when the second operand is greater than the first operand. This makes sense when you look at what is going on behind the scenes.

CMP.W D1,D0 ;Performs D0-D1, sets the CCR, discards the result 

It sets the CCR (Condition Code Register) because the branch is taken only when (N=1 and V=1 and Z=0) or (N=0 and V=0 and Z=0).

Now to transform:

if (D0 > D1) {
    //do_some_stuff
} else {
    //do_some_other_stuff
}

Into 68k assembly language:

     CMP.W   D1,D0       ;compare the contents of D0 and D1
     BGT     IF 
     // do_some_other_stuff
     BRA     EXIT
IF
     // do_some_stuff
EXIT ...
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top