newb: What is different between r0-r15 and r16-r31?

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

Hi - I have noticed that some AVR assembler instructions only work with registers r0-r15, while some work only with registers r16-r31 (such as LDI). Can anyone tell me what is different between these two sets of registers? Are r0-r15 used for some special function or something? Thanks, and sorry for such a simple question - I'm very new to the world of AVRs!

edit: by the way - if it matters - currently I'm only using AT90S8515 AVRs.

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

Yes, there are certain instructions that only apply to a certain subset of the genreal-purpose registers (GPRs).

If you look at the bit encodings for the instructions, the chip designers just plain ran out of room for all the instruction-operand combinations, so some instructions are limited in register selection.

It is an annoyance, but once you get a feel for the rules it is not much of a hindrance.

Lee

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

To elaborate on what Lee said, all of the instructions that operate on a register and an immediate value only take a register in the range of r16 to r31.

These instruction end in 'I'... SUBI, SBCI, ANDI, ORI, LDI, and CPI. SBR, CBR, and SER are also limited to the high registers, as these are really ORI, ANDI, and LDI instructions respectively.

I hope I didn't miss any...

Edit:
I didn't really answer your question now did I?
What I usually do in assembly programs is use the low registers to hold global data or anything that I need to access regularly throughout the program but that dont need to occupy SRAM. The high registers, since you can do immediate operations on them, are more suited to be used for variables local to each function.

/* John Butera */

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

try this for a detailed description of every instruction:
http://www.atmel.com/dyn/resourc...
there you can also find the register-usage, etc. (just as an additional info!)

till then, sebastian...

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

All hail the instruction set! :D

/* John Butera */

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

I've been wondering about that.

Thanks to Pepsi and a bit of insomnia, I know :)

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

The difference between r0-r15 and r16-r31 is.... 16.

OK, slap me. :P

Regards,
Scott