ARM Assembler - How do I use CMP, BLT and BGT?

前端 未结 3 593
北荒
北荒 2021-02-09 12:29

Quick question for you guys, in my loop I need to use CMP , BLT and BGT to compare some values. How would use said instructions in the following loop?

I\'m trying to use

3条回答
  •  旧时难觅i
    2021-02-09 12:43

    You cannot do a conditional branch without first setting the condition register somehow. This can be done with cmp or by adding s to most instructions. Check out the ARM assembly documentation for details. Quick example:

    Branch if r0 greater than 5:

    cmp r0, #5 ;Performs r0-5 and sets condition register
    bgt label_foo ;Branches to label_foo if condition register is set to GT
    

    Compare r6 with r4 , put difference into r7, branch if r7 < 0:

    subs r7, r6, r4 ;Performs r7 = r6 - r4 and sets condition register
    blt label_bar ;Branches to label_bar if r7 < 0 (in which case r6 < r4)
    

提交回复
热议问题