Current program counter in AVR-Asm

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

Hi!

Im looking for a feature that lets me write jumps relative the current program counter. For example when writing polling loops:

polling: SBRS flagregister,someflag
RJMP polling

I don't want to define a new label for every such poll. I have also programmed PIC-microcontrollers and in mpasm you can use:

SBRS flagregister,someflag
RJMP $-1

where $-1 means one step back, i.e. the current program counter value minus one.

Does anyone know if this is possible in AVR Assembler? If not, this is probably an nice feature for the developers of AVR Assembler to implement!

Regards
/Marcus Rudberg - Student Chalmers University of thecnology

admin's test signature
 

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

Try: rjmp PC-1

-Geir

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

However, your code will be more readable if you do use a label for the target point. Will often avoid the need for a comment on the line. For example:

waitForHotWater:
sbrs flagregister,someflag
rjmp waitForHotWater

[another tip .. use lowercase for the instruction codes .. again, a little easier to read and less error-prone]

admin's test signature
 

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

Furthermore, if you use the "PC+/-xx" syntax you'll easily fall into the "2 word instructions" trap (like e.g. call or sts are assembled into *two* words instead of the usual one). I've been there ...

Using PC+/-offset (like playing with the IP reg in the x86 world) looks *very* professional - no ugly labels to think up etc.

Very clean.

Also, usually, very error prone and a great means to make your code unreadable.

I'll use this technique only inside macro definitions.

admin's test signature
 

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

Thanks for all tips

/Marcus

admin's test signature
 

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

You can use labels inside macros too!
I made many projects before I found this !
Pawel

admin's test signature