Last active
December 21, 2019 09:05
-
-
Save Matts966/9ede73330da5424c3f9e2a8e361e2616 to your computer and use it in GitHub Desktop.
Write multiple line assembly in Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { | |
} |
Author
Matts966
commented
Dec 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment