Noob here, learning Assembly.
I'm trying to use code ROM data storage on an ATmega328p (Arduino) but I can't get it to work.
This is what I have so far:
#define __SFR_OFFSET 0 #include <avr/io.h> .equ RAM_BUF, 0x0140 ; The SRAM location the string needs to be moved to. ; Initialisation ldi ZH, hi8(STRING) ldi ZL, lo8(STRING) ldi XH, hi8(RAM_BUF) ldi XL, lo8(RAM_BUF) ; Main program LOOP: lpm r20, Z+ cpi r20, 0 breq STOP st X+, r20 rjmp LOOP STOP: rjmp STOP ; Fixed data storage .data STRING: .asciz "Hello, World!\n"
The code compiles without error, but the string never gets loaded. Instead R20 gets the value 0xFF every time and thus the LOOP never ends as well.
I am following the Mazidi book "AVR in assembly and C" so only have Atmel assembly code as examples.
The GNU-AS manual is very terse about directives and my Google Fu is failing me.
For what its worth, I tried setting the Z register with
ldi ZH, hi8(STRING << 1)
But that produces Error: invalid operands (.data and *ABS* sections) for `<<'
Can anyone point me in the direction of resources for translating Atmel directives to GNU?