/*
Program for the Lecture 2.2.3
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: I will explain the steps to recover reliably whenever
the program becomes unresponsive because of wrong assembly programs
which may hang the board due to some errors in your program.
CAUTION2: DO NOT UPLOAD this program with
Raspberry Pi RP2040 Boards (1.4.0) --> Raspberry Pi Pico
*/
#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 add_asm_fn(void);
unsigned int flags_add_asm_fn(void);
}
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
Serial1.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
unsigned int add_ret_val;
unsigned int flags_ret_val;
add_ret_val = add_asm_fn();
myPrint("add_asm_fn()", add_ret_val);
flags_ret_val = flags_add_asm_fn();
myPrint("flags_add_asm_fn()", flags_ret_val);
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
} // end of loop()
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);
Serial1.println(); // print an empty line
} // myPrint(char*, int)