Can anyone help me get this code compiled? It's my first stab at assembly and I'm having a heck of a time.
#define mp r16 ; Until now, no data has been written. Here is where ; the program start address is defined. ; Whenever the AVR is restarted it starts the program ; execution at address 0000. rjmp main ; relative jump to main ; relative jump means that the relevent ; distance is added to the current execution ; execution address and the program is executed ; at the new address ; So this is the start (0000) main: ldi mp,0b11111111 ; put 8 bits (maximum value) into ; register r16. ; 0b denotes binary ; ldi means "load immediate" ; - only works on registers r16 - r31 out DDRD,mp ; write the register value (r16) to port DDRD ; this will turn on port D for output loop: ldi mp,0x00 ; load eight zero bits into mp out PORTD,mp ; copy the register value to PORTD ; when the zeros are set the LEDs will be _ON_. ; this is because they are connected to the ; voltage resistors of 1 k (0 = on, 1 = off). ldi mp,0xFF out PORTD,mp rjmp loop
This is basically scrapped together from some examples I've found on the internet.
When I attempt to compile the code I get the following error:
-------- begin -------- avr-gcc (GCC) 4.2.1 Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Assembling: led.S avr-gcc -c -mmcu=attiny2313 -I. -x assembler-with-cpp -Wa,-adhlns=led.lst,-gstabs led.S -o led.o Linking: led.elf avr-gcc -mmcu=attiny2313 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=led.o -std=gnu99 led.o --output led.elf -Wl,-Map=led.map,--cref -lm /usr/lib/gcc/avr/4.2.1/../../../../avr/lib/crttn2313.o: In function `__bad_interrupt': ../../../../crt1/gcrt1.S:123: undefined reference to `main' make: *** [led.elf] Error 1
I'm using the avr-gcc toolset under linux and I've been able to get a couple of simple C examples working just fine. It seems like I'm missing something in the linking process but I don't know enough yet to figure it out. Any help would be great!