0

so I'm trying to study for this test and one of the things on the study guide gives us some ARM Code and tells us to fill in a branch prediction table based on how the code runs.

I can understand how I'm supposed to do it, but with branch prediction the actual outcome comes into play, too, and I can't figure out the outcome (per cycle) from the code. The code is:

    MOV r0, #4
B1  MOV r2, #5; Branch 1
    SUB r2, r2, r0
B2  SUBS r2, r2, #1; Branch 2
    BNE B2
    SUBS r0, r0, #1
    BNE B1

What's confusing me is the BNE statements. Usually when I see one of those conditional statements there has been a CMP statement earlier in the code, and that way I can know whether to take the branch or not. But I see no compare statement anywhere in this code, so I don't know how to determine if I should take a branch or not.

PCRevolt
  • 129
  • 1
  • 1
  • 8
  • you have a subs, look that up in the arm architectural reference manual. also there is more than one kind of branch prediction (supported by various arm cores), which one are you talking about (again read the arm docs). – old_timer Dec 01 '17 at 12:27
  • and does branch prediction mean you are guaranteeing that you figured out the branch early? or there is a possibility of branching early so lets toss a fetch in just in case? – old_timer Dec 01 '17 at 12:28
  • and you cant really determine cycle accuracy (without getting very specific into the core, build options, chip design/options and performance), so unclear what you are asking. – old_timer Dec 01 '17 at 12:29
  • Oh, I think I figured it out. So SUBS just checks if the register is equal to 0 and then the BNE statement branches if it's not. I thought only CMP statements worked in these situations. Thanks, though. – PCRevolt Dec 02 '17 at 00:14
  • depends on the instruction set some every instruction touches the flags, some it is optional if instructions touch the flags, some cmp is used to touch flags and some dont have flags. And no that is not what that instruction is doing. – old_timer Dec 02 '17 at 00:28

1 Answers1

0

The SUBS performs a subtraction and a comparison with zero of the result in one instruction. The BNE conditional branches use the condition flags that were set by these SUBS instructions

Kyrill
  • 2,963
  • 1
  • 8
  • 12