3

I have problem with stack init lines because avr-gcc returns

LED_Blink.asm:10: Error: garbage at end of line

On lines:

ldi r17, low(RAMEND)
ldi r17, high(RAMEND)

And I am confused. I have already defined RAMEND. I used avr-gcc with this command:

avr-gcc -x assembler -mmcu=atmega328p LED_Blink.asm

My assembly code:

.equ    SPL, 0x3d
.equ    SPH, 0x3e
.equ    RAMEND, 0x8ff

.equ    PORTB, 0x05
.equ    DDRB, 0x04
.org    0x000000
rjmp main
main:
    ldi r17, low(RAMEND)
    out SPL, r17
    ldi r17, high(RAMEND)
    out SPH, r17

    ldi r16, 0xff
    out DDRB, r16
    out PORTB, r16
loop:
    ldi r16, 32
    rcall outer_loop
    cbi PORTB, 5
    ldi r16, 32 
    rcall outer_loop
    sbi PORTB, 5
    rjmp loop
outer_loop:
    clr r24
    clr r25
delay_loop:
    adiw r24, 1
    brne delay_loop
    dec r16
    brne outer_loop
    ret
Rišo Baláž
  • 75
  • 1
  • 4

1 Answers1

7

low and high don't mean anything to the GNU assembler for AVR, I think you want to use lo8 and hi8 to take the low and high bytes, respectively.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • Useful ink: http://sourceware.org/binutils/docs-2.21/as/AVR_002dModifiers.html#AVR_002dModifiers – Paul R Dec 19 '15 at 08:03
  • @PaulR semi-useful anyway. It implies that it's only appropriate for addresses, which doesn't seem to be the reality — it works okay on constants too :) – hobbs Dec 19 '15 at 08:05
  • Thank you. It seems to be passing. But I am getting another problem with that: avr-gcc -Wall -g -mmcu=atmega328p -o LED_Blink.elf LED_Blink.o /usr/lib/gcc/avr/4.8.1/../../../avr/lib/avr5/crtm328p.o:(.init9+0x0): undefined reference to `main' collect2: error: ld returned 1 exit status – Rišo Baláž Dec 19 '15 at 08:19
  • Solved. Just remove the -mmcu=atmega328p. – Rišo Baláž Dec 19 '15 at 08:42