Register aliases??

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

In an AVR assembly tutorial http://www.avr-asm-tutorial.net/avr_en/beginner/REGISTER.html#Unterschied
there was a list of notes about register usage:

Quote:
Recommendation for the use of registers

Define names for registers with the .DEF directive, never use them with their direct name Rx.
If you need pointer access reserve R26 to R31 for that purpose.
16-bit-counter are best located R25:R24.
If you need to read from the program memory, e.g. fixed tables, reserve Z (R31:R30) and R0 for that purpose.
If you plan to have access to single bits within certain registers (e.g. for testing flags), use R16 to R23 for that purpose.


It's the first one that caught my eye.
WHY aliases?
Is that customary in "AVR-circles"?
I've never done that, and I guess it would "hide" the possible restrictions if alias is used.

Debugging is for sissies and delivery for surgeons. Real men do demonstration.

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

Just lets you give them sensible names. The code:

.def counter = r16

  clr counter
loop:
  call do_something
  inc counter
  cpi counter, 10
  brne loop

is easier to read than

  clr r16
loop:
  call do_something
  inc r16
  cpi r16, 10
  brne loop

In the first it's immediately obvious that r16 is being used as a counter.

Also if you put all your .def in one place then you can quickly see that of the r16..r31 registers you have already used r16, r17, r18, r19 and when you need a new variable r20 would be the next one to use. Without the .def you have to scan over the whole code to see "ah yes, I'm using 16 here, oh and 17 there, oh and I see 18 and 19 here - so 20 it is"