0

I am new to ARM Cortex and facing difficulty to understand how TBB branches.

Code snippet attached:

TBB [PC,R1]
BrTable1 
DCB ((P0 - BrTable1)/2) 
DCB ((P1 - BrTable1)/2)

Now, my understanding is as follows:

TBB [PC,R1] will try to look for BrTable1 at PC + 4 (next instruction). Instead of PC, I can also give BrTable1 pointer here. R1 is counter and for next N cycles depending on R1 possible values, it will have cases.

Branching will happen as : PC_new = (BrTable1_pointer) + 2 * (data written at BrTable1_pointer + R1)) whereas R1 will be as a up-counter from 0 to X (For 8 bit, X = 255)

For R1 = 0, DCB ((P0 - BrTable1)/2) will

  • Branch my code to (BrTable1 + 2 * ((P0 - BrTable1)/2))
  • Branch my code to (BrTable1 + (P0 - BrTable1))
  • Branch my code to P0

Now this is as per expectation also.

Query

Intention is to compare the value of R1 and accordingly branch.

  1. Is my understanding correct?
  2. If I want to write only 2 cases for R1 == 0 and R1 == 10 then should I write my DCB instruction at ( BrTable1 + 10 ) location or is there any method to write it in next instruction only?
  3. Do I have any control on R1?

Description

3
  • Apart from the “for next N cycles” bit, which I'm not sure what it means, this seems to be correct. Though note that all of R1 is used, not just the low 8 bits. TBB is particularly useful for dense branch tables. If your table is sparse, it might be better to just use a conditional branch or two.
    – fuz
    Commented May 16 at 12:04
  • 1
    Please do not upload images of code/data/errors. Copy the code into a code block instead (see my edit of your code snippet for how to correctly format a code block).
    – paleonix
    Commented May 16 at 13:50
  • @LalitArora Always happy to help, but please do edit your question and replace your picture with code.
    – fuz
    Commented May 23 at 11:00

0

Browse other questions tagged or ask your own question.