0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

いろいろなボードでArduinoでインラインアセンブラを使ってみる

Posted at

参考

動かしてみたボード

  • NUCLEO F303K8
  • NUCLEO G070RB
  • Seeed XIAO
  • Raspberry Pi Pico(互換のRP2040ボード)

使ったコード

asm_test.ino
void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  Serial.println("Boot NUCLEO");

  int a=1, b=2, c=3; 

  Serial.print("a = ");
  Serial.print(a);
  Serial.print(" b = ");
  Serial.print(b);
  Serial.print(" c = ");
  Serial.println(c);

  // res = i + j;
  asm volatile (
     "ADD %[result], %[input_i], %[input_j]"
     : [result] "=r" (a)
     : [input_i] "r" (b), [input_j] "r" (c)
     );

  Serial.print("a = ");
  Serial.print(a);
  Serial.print(" b = ");
  Serial.print(b);
  Serial.print(" c = ");
  Serial.println(c);
}

void loop() {
}

実行例

$ arduino-cli compile --fqbn STMicroelectronics:stm32:Nucleo_32:pnum=NUCLEO_F303K8 asm_test
最大65536バイトのフラッシュメモリのうち、スケッチが11620バイト(17%)を使っています。
最大12288バイトのRAMのうち、グローバル変数が1184バイト(9%)を使っていて、ローカル変数で11104バイト使うことができます。

Used library Version Path                                                                                                   
SrcWrapper   1.0.1   /Users/numeru55/Library/Arduino15/packages/STMicroelectronics/hardware/stm32/2.5.0/libraries/SrcWrapper

Used platform            Version Path                                                                              
STMicroelectronics:stm32 2.5.0   /Users/numeru55/Library/Arduino15/packages/STMicroelectronics/hardware/stm32/2.5.0

$ arduino-cli upload --fqbn STMicroelectronics:stm32:Nucleo_32:pnum=NUCLEO_F303K8 asm_test
Found 'NODE_F303K8' at '/Volumes/NODE_F303K8'
Copying /private/var/folders/c_/wzylbygj0b9cc551z53rjr7r0000gn/T/arduino/sketches/AE97D6A7E80798B6833F891E3602AF0E/asm_test.ino.bin to /Volumes/NODE_F303K8...

$ arduino-cli monitor -p /dev/cu.usbmodem14103
Connected to /dev/cu.usbmodem14103! Press CTRL-C to exit.
Boot NUCLEO
a = 1 b = 2 c = 3
a = 5 b = 2 c = 3
^C
$
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?