AVR-GCC: Error: garbage at end of line

2019-04-11 23:54发布

问题:

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

回答1:

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.