Arduino IDE not compile .S program to board After answering my previous question correctly I'm getting all sorts of errors when trying to compile the following program:

I'm completely new to both assembly and the arduino IDE so I apologise in advance for any basic errors.

sketch.ino:

#include "blink.S"
extern void blink();
void setup() {
  // put your setup code here, to run once:
blink();
}

void loop() {
  // put your main code here, to run repeatedly:

}


blink.S file:

#define __SFR_OFFSET 0
#include &lt;avr/io.h&gt;         




  .section .text


  ldi r18, 0x20   ; loading 0x20 = 00100000 into register r18
  out DDRB, r18   ; making pin 5 of port B an output

  mov r16, r18    ; copy mask 00100000 also to r16

loop: out PORTB, r16    ; switch on or off the pins of port B
        ; according to bit pattern in r16


  ldi r17, 82   ; 1000ms delay, see below

outer_delay:
  clr r1      
middle_delay:
  clr r2      
inner_delay:        
  dec r2      ; 1 clock tick
  brne inner_delay  ; 2 clock ticks when z!=0, 1 tick when z=0.

  dec r1      ; when this line is reached, about
        ; 256*3 = 768 ticks have been consumed since inner_delay.
  brne middle_delay ; 

  dec r17                 ; when this line is reached, about
        ; 256*256*3 = 196608 ticks have been
        ; consumed since middle delay.
  brne outer_delay  

  eor r16,r18   ; invert bit 5 in r16 using exclusive or.
  rjmp loop   ; jump back to loop.
There's four things I can see wrong (one of which is my fault, actually - I should have mentioned it in the previous question - nevermind).

Firstly you cannot include a .S file in a .INO file. A .S file is assembly, a .INO file is C++. You can't mix the two in one file (and including a file does just that - includes the file verbatim at that point). So remove that #include. Otherwise it would be like opening a book written in English only to find the preface is written in Klingon.

Secondly you need to give your function a name. It doesn't have one at the moment. Naming the file is not naming the function.

So you need to provide a label at the entry point:

  .section .text

blink:    ; &lt;&lt; This is the name of the function
  ldi r18, 0x20   ; loading 0x20 = 00100000 into register r18
  out DDRB, r18   ; making pin 5 of port B an output


Third you need to export that name as a global symbol:

  .section .text
  .global blink ; &lt;&lt; This exports the function name

blink:    ; &lt;&lt; This is the name of the function
  ldi r18, 0x20   ; loading 0x20 = 00100000 into register r18
  out DDRB, r18   ; making pin 5 of port B an output


And finally you have the problem of linkage name munging.  You're linking a C++ file with (ostensibly) a C file - and C++ munges names. So you have to tell your C++ file that the function is not a C++ function, but a C function (which is what I should have mentioned previously):

extern "C" void blink(); // &lt;&lt; Add the "C" to tell it not to munge the name

void setup() {
  // put your setup code here, to run once:
  blink();
}

void loop() {
  // put your main code here, to run repeatedly:
}