#概要
wemos d1でアセンブラやってみた。
#サンプルコード
extern "C" {
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "user_interface.h"
}
byte YELLOW_pin = 4;
byte BLUE_pin = 12;
void toggle_blue_yellow__asm()
// yellow pin = 4 => bit mask = 16d, [0...0]10000 (32 bit)
// blue pin = 12 => bit mask = 4096d, [0...0]1 0000 0000 0000 (32 bit)
// PIN_OUT_SET : 0x60000304
// PIN_OUT_CLEAR : 0x60000308
//
{
asm volatile (
"movi a2, 0x60000304;" // SET Address in a2
"movi a3, 0x60000308;" // CLEAR Address in a3
"movi a4, 16;" // yellow pin bit mask in a4
"movi a5, 4096;" // blue pin bit mask in a5
"movi a6, 12;" // delay loop counter
"s32i a4, a3, 0;" // set yellow to LOW
"memw;"
"s32i a5, a2, 0;" // set blue to HIGH
"memw;"
"label1:"
"addi a6, a6, -1;"
"NOP;"
"NOP;"
"NOP;"
"NOP;"
"bnez a6, label1;"
"movi a6, 12;" // delay loop counter
"s32i a4, a2, 0;" // set yellow to HIGH
"memw;"
"s32i a5, a3, 0;" // set blue to LOW
"memw;"
"label2:"
"addi a6, a6, -1;"
"NOP;"
"NOP;"
"NOP;"
"NOP;"
"bnez a6, label2;"
"movi a6, 12;" // delay loop counter
"s32i a4, a3, 0;" // set yellow to LOW
"memw;"
"s32i a5, a3, 0;" // set blue to LOW
"memw;"
"label3:"
"addi a6, a6, -1;"
"NOP;"
"NOP;"
"NOP;"
"NOP;"
"bnez a6, label3;"
"movi a6, 12;" // delay loop counter
"s32i a4, a2, 0;" // set yellow to HIGH
"memw;"
"s32i a5, a2, 0;" // set blue to HIGH
"memw;"
"label4:"
"addi a6, a6, -1;"
"NOP;"
"NOP;"
"NOP;"
"NOP;"
"bnez a6, label4;"
::
: "a2", "a3", "a4", "a5", "a6", "memory"
);
}
void setup()
{
pinMode(YELLOW_pin, OUTPUT_OPEN_DRAIN);
pinMode(BLUE_pin, OUTPUT_OPEN_DRAIN);
}
void loop()
{
delay(10);
toggle_blue_yellow__asm();
}
以上。