0

I am trying to achieve something similar to the following C code:

if(x<0)
{
    <code A>
}
else if(x == 0)
{
    <code B>
}
else        //x > 0
{
    <code C>
}
postIf code

So i was wondering if I could do this by doing the following in ARMv8, AArch64 instruction set:

    cmp x_r, 0     //x_r macro for x19
    b.lt neg
    b.gt pos

    <code B>
    b postIf

neg:
    <code A>
    b postIf
pos:
    <code C>
postIf:
    <postIf Code>

Does this work? Do flags stay set (or not set) after checking a conditional branch?

Erick P
  • 87
  • 1
  • 2
  • 9
  • 1
    the arm documentation indicates that a branch does not modify the flags. they also list the instructions that modify the flags. – old_timer Apr 11 '17 at 00:06
  • also trying a test program you will see that the compiler assumes/knows that the flags are not affected. – old_timer Apr 11 '17 at 00:07
  • There are a lot of conditionals in ARMv8 that should help you. https://www.element14.com/community/servlet/JiveServlet/previewBody/41836-102-1-229511/ARM.Reference_Manual.pdf – InfinitelyManic Apr 11 '17 at 01:53

1 Answers1

1

Yes, that should work fine. Branch instructions do not modify the flags.

apt1002
  • 969
  • 6
  • 15