0
\$\begingroup\$

I am currently trying to indirectly address the SRAM of the ATMega328P by using the following code:

ldi XL, 0b11111111 ;load pointer ldi XH, 0b00001000 ldi r16, 0b01001011 ;load value sts X, r16 ;write value 

However, AVRA detects an error in the given code:

main.asm(51) : Error : Found no label/variable/constant named X 

I don't know, what is wrong with my code because I found similar examples online (http://www.rjhcoding.com/avr-asm-sram.php).

\$\endgroup\$
4
  • \$\begingroup\$ so, what is this X that you want to store to? Both your assembler and I are wondering about that. \$\endgroup\$ Commented Jun 21, 2024 at 16:57
  • \$\begingroup\$ X was supposed to be the X-pointer consisting of XL and XH. It is used the same way in the linked example. \$\endgroup\$ Commented Jun 21, 2024 at 17:01
  • \$\begingroup\$ OK, but why do you use a register for the instruction that is called "Store direct to memory space"? I think this is just a matter of you not having selected the right instruction for your task \$\endgroup\$ Commented Jun 21, 2024 at 17:03
  • \$\begingroup\$ Oh, I see. I should just use "st", right? \$\endgroup\$ Commented Jun 21, 2024 at 17:08

1 Answer 1

2
\$\begingroup\$

You are using the wrong opcode.

If you want to store contents of some register to memory pointed by X, you use

ST X, r16

STS takes in an immediate address for where you want to store a register (and you have no label X with immediate address)

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.