Relative branching on the PRU

I have been trying how to find a way to do a relative branch (from the current instruction pointer) for a branch.

I have something like this:

`

.macro SETBIT
.mparam reg,bit,lab,lab2
QBBC lab, BYTE_VALUE,bit
SET r30, 14
QBA lab2
lab:
CLR r30,14
lab2:

`

What I would like to do is on the first QBBC, provide a relative label (so I don’t have to pass a unique name to the macro. The same for QBA lab2.

On a PIC one can do a $+#, where $ is the current instruction pointer, and the # is is the number of instructions to jump forward (or backward if negative). Is something like this possible?

I have been trying how to find a way to do a relative branch (from the
current instruction pointer) for a branch.

You can read the program counter into a register, add an offset, and
then use a plain jump (to the register contents), but the quick-branch
instructions are already relative.

I have something like this:

.macro SETBIT
.mparam reg,bit,lab,lab2
        QBBC lab, BYTE_VALUE,bit
        SET r30, 14
        QBA lab2
lab:
CLR r30,14
lab2:

What I would like to do is on the first QBBC, provide a relative label (so
I don't have to pass a unique name to the macro. The same for QBA lab2.

On a PIC one can do a $+#, where $ is the current instruction pointer, and
the # is is the number of instructions to jump forward (or backward if
negative). Is something like this possible?

I'm not sure why you don't just put the labels inside the macro, where
they will be local in scope (see 5.3.3.1.1 "Defining a Macro" in the PRU
Reference Guide). If that doesn't solve your problem, perhaps a bit
more code would help to exhibit the particular issue you're trying to
overcome.

If I put the labels in the macro, then I will get a duplicate label (for the macro will be expanded out, and have multiple labels.

I have worked around this, by having the labels passed in, but would like to not have to do that.

Or is there something I am missing about scope on macros?

Hi Charles,

It's been too long and I can't remember if this is something I fixed in my assembler, but I use the following macro in my code without a problem:

   136 : : .macro assert_bit_clear
   137 : : ; ---------------
   138 : : .mparam p1
   139 : : .mparam p2
   140 : : QBBC Ldone, p1, p2
   141 : : HALT
   142 : : Ldone:
   143 : : .endm
   144 :

If this doesn't work with the assembler you're using, have a look at my version here: https://github.com/modmaker/am335x_pru_package

-- Bas

Or is there something I am missing about scope on macros?