Using registers with ASM

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

Simple Q I suspect, but when you don't know the answer...

All the example code I ever see uses r16 onwards and so in my apps I do the same.

Why not use r0-r15? Either in example code or my own apps...

TIA, Martin

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

Quick "hint":

Instructions like LDI, ORI, ANDI only work with R16->R31 ...

Ex.

ldi r16, 10    OK!
ori r21, 0x40 OK!

ldi r0, 10      NOT OK!
ori r5, 20     NOT OK !

Check the instruction set for details ...

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

You can use any of the registers for most operations, but only r16-r31 can be used with imeadiate operation such as ldi. Also note that the top 6 registers are also the 16-bit register pairs X, Y, and Z, which can be used as pointers and have additional instructions that work with them.

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

Okay, thanks for the tips guys!

I know I could find all the above if I RTFM but I'm just trying to save some time. I could spend days sifting through all those PDFs.

So quick summary is no immediate instructions with r0-15 and top 6 bytes (R26:R25, R28:R29, R30:R31) are typically set-aside as pointers X, Y, Z.

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

You first register pair should be r26:r27. Also note that some instructions like adwi will also work with r25:r24.