0
votes

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?

1
the arm documentation indicates that a branch does not modify the flags. they also list the instructions that modify the flags. - old_timer
also trying a test program you will see that the compiler assumes/knows that the flags are not affected. - old_timer
There are a lot of conditionals in ARMv8 that should help you. element14.com/community/servlet/JiveServlet/previewBody/… - InfinitelyManic

1 Answers

1
votes

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