Search code examples
assemblyconditional-statementsarmbranchless

How to Compare two registers and perform action if greater than without branching in ARM


I am trying to compare two registers r5 and r6 which I know I can do with

CMP R7, R5

What I am trying to do is

if R7 > 1 then ADD R8, R8, #1 Without branching as I will be using this multiple times in different sections of the code

I know BGT will branch if greater than, or if its possible to return to previous position after branching to add to count?


Solution

  • Many ARM instructions are defined as OP{cond}, this means you can make the execution of this instruction depend on a condition:

    cmp r5, r7
    addgt r8, r8, #1 //increments r8 if r5 is greater than r7
    mov r1, r0 //executes in any case