I am trying to write an assembly program to add two numbers (working with ATmega328P). The task requires adding the value in r5 (specifically 0x88) to the value in memory location 0x0260 and storing the result in memory location 0x0360. Here is what I have written so far:
.include "m328pdef.inc"
ldi r5, 0x88
lds r1, 0x0260
add r5, r1
sts 0x0360, r5
end: rjmp end
If I replace the register names with r16 and r18, the program works. However, when using r5, the program gives an "Invalid register" error.
What to do? The assignment requires using register number 5.
I googled a little bit and found out that LDI only works on the upper 16 registers - R16-R31. So I decided to do LDI stuff to r16 and then MOV it to r5.