AVR R0 to R15

Status
Not open for further replies.

lord loh.

Member
How on earth do I access R0 to R15 of the general purpose registers? Whenever I try
Code:
ldi r0,0x01
I get an error called invalid register...

Where could I have gone wrong...

Please excuse me if the question is dumb and help me out.

Thank You.

______
Added a few minutes later:

Okay, I discovered that the instruction LDS to load into all 32 registers but the con is that it is a 2 word instruction unlike the ldi which is a single word instruction.

If anyone has anything to add that might clear any misconception that I have, please do so.
 
Last edited:
LDI only works on the upper 16 registers - R16-R31. There is no way of loading the lower 16 registers directly (I guess they ran out of instruction bits).

When doing assembly code, I usually leave the lower 16 registers for use as global state/temporaries
 
It is the case that there are not enough bits in the instruction word to allow ldi for all 32 registers. Write a two instruction sequence with a macro that does an ldi to R16 and then moves R16 to another register.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…