/*
Program
This needs to be built with the board package of MBedOS
(Arduino MbedOS RP2040 boards --> Raspberry Pi Pico
If you try to upload this program with other Pico board choices,
the board will become unresponsive.
CAUTION1: You need to follow the steps that you did when you
connected the new board for the first time (pressing BOOTSEL)
whenever the program becomes unresponsive because of wrong
assembly programs which may hang the board due to some
errors in your program.
*/
#include<stdio.h>
#include<stdlib.h>
// Uncomment this if when you copy this code to run it on HW
//#define RUN_ON_HW
#ifdef RUN_ON_HW
#define Serial1 Serial
#endif
void myPrint(char* fnName, unsigned int result);
// Define external assembly function
extern "C" {
unsigned int my_asm_fn(void);
}
// the setup function runs once when you press reset or power the board
void setup() {
// Initialize serial communication
Serial1.begin(9600);
// Initialize built-in LED pin as an output
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
unsigned int asm_ret_val;
// Call the assembly function and receive the result in R3
asm_ret_val = my_asm_fn();
// Print the result returned from the assembly function
myPrint("my_asm_fn()", asm_ret_val);
// Blink the built-in LED
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
} // end of loop()
// Print function to display results
void myPrint(char* fnName, unsigned int printVal) {
Serial1.print("The value returned from the assembly fn ");
Serial1.print(fnName);
Serial1.print(" : ");
Serial1.println(printVal);
Serial1.print("The value returned from the assembly fn ");
Serial1.print(fnName);
Serial1.print(" in Hex: 0x");
Serial1.println(printVal, HEX);
} // myPrint(char*, int)