How do I create a branch target label in a macro?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I haven't needed to do this in decades, but I do now.  I need to create a local label inside an assembly language macro such that it (obviously) is different for each invocation of the macro.  I saw something online that talked about a LOCAL directive, but I don't see that in the assembler documentation.  Back in the 1980s I knew how to do this. :)

 

Last Edited: Sun. Jun 6, 2021 - 07:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may pass to the macro a different letter that will make the label different, can you try it.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kk6gm wrote:
I need to create a local label inside an assembly language macro

You will need to specify the toolchain.  Atmel assembler will be different from GCC assembler.  [Isn't that one of the things that AVRASM2 cannot do?]  Others may be unique as well.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the gcc assembler, you have ugly but useful numeric local labels:

 

0: cpi r14, 0   ;;; delay function, badly written
   breq 1f      ;;; jump forward to label 1
   subi r14, 1
   rjmp 0b      ;;; jump backward to label 0
1: ;;; exit the delay loop.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
In the gcc assembler, you have ugly but useful numeric local labels:
Ugly is overstating the case.

I'll grant that they are not gorgeous.

The same may be said of alternatives.

Moderation in all things. -- ancient proverb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kk6gm wrote:

I haven't needed to do this in decades, but I do now.  I need to create a local label inside an assembly language macro such that it (obviously) is different for each invocation of the macro.  I saw something online that talked about a LOCAL directive, but I don't see that in the assembler documentation.  Back in the 1980s I knew how to do this. :)

 

There's no such thing in C or C++ preprocessor as "LOCAL directive". What are you talking about?

 

A fairly usable way to create local names in a macro definition is concatenating prefixes with `__LINE__` value. This relies on the fact that all macro definitions are essentially a single line chopped up by `\` splitters and `__LINE__` produces the same value everywhere in a single macro definition.

 

There's no way to say more without seeing the actual code.

 

 

Dessine-moi un mouton

Last Edited: Fri. Jun 11, 2021 - 08:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>What are you talking about?

 

>a local label inside an assembly language macro

 

 

The c/c++ preprocessor is not the only owner of macros.

 

https://sourceware.org/binutils/...

 

 

>There's no way to say more without seeing the actual code.

 

Something like #5 is most likely what is wanted. Surround it with .macro delay/.endm and you have an example. Invoke it once or 100 times and your labels remain unique.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I gave up on trying to figure out labels inside macros.  Too much effort for not enough benefit (but after I typed this, I saw #5, which I somehow didn't grok the first time around).  Using simple .-N is enough for my needs.  But now I have another macro problem which I'll post in a new thread.

 

FURTHER EDIT:  Thanks to westfw and also curtvm, I'm going with the 0: 0b local labels.  Much appreciated.

 

FINAL EDIT: My other problem was figuring out how to pass parameters into a macro.  @0,@1 didn't work.  I finally stumbled (via an old post here) onto mymacro r, d with arguments referenced as \r, \d.

Last Edited: Sat. Jun 12, 2021 - 07:46 PM