Skip to content

Instantly share code, notes, and snippets.

@Matts966
Last active December 21, 2019 09:05
Show Gist options
  • Save Matts966/9ede73330da5424c3f9e2a8e361e2616 to your computer and use it in GitHub Desktop.
Save Matts966/9ede73330da5424c3f9e2a8e361e2616 to your computer and use it in GitHub Desktop.
Write multiple line assembly in Arduino
// single line example
#define ASM(x) asm volatile(x "\n\t")
void setup() {
ASM("ldi r16, 0b00001000");
ASM("out 0x17, r16");
ASM("ldi r19, 1");
ASM("ldi r20, 1");
task();
}
// multi line example
void task() {
asm volatile(R"(
task1:
ldi r16, 0b00001000
out 0x18, r16
rcall delay0
ldi r16, 0b00000000
out 0x18, r16
rcall delay0
rjmp task1
delay0:
ldi r17, 0
delay1:
ldi r18, 0
delay2:
dec r18
brne delay2
dec r17
brne delay1
ret
)");
}
void loop() {
}
@Matts966
Copy link
Author

asm volatile(R"(
// You can write here!
)");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment