/*
* Lab9_Params_Flags_asm_framework ... on 8 Oct 2021 (Fri, 9:30 am) - modified
* the function signature of the getMaxUnsigned()
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 it while running on Wokwi Simulator
#define RUN_ON_WOKWI
#ifdef RUN_ON_WOKWI
#define Serial Serial1
#endif
void myPrint(char* fnName, int result);
bool resFlag = false;
int resVal = 0;
unsigned uResVal = 0; // Newly added for receiving the value returned by getMaxUnsigned()
// Define external assembly function
extern "C" { // Implement the last three problems
unsigned int get_cpsr0(void);
unsigned int get_cpsr1(void);
bool isEqual(int param1, int param2); // It's implementation is given as a demo
bool isNegative(int param1);
int getMinSigned(int param1, int param2, int param3, int param4);
unsigned getMaxUnsigned(unsigned param1, unsigned param2,
unsigned param3, unsigned param4);
}
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
unsigned int cpsr_val;
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // Mouli // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(2000); // Mouli // wait for a second
cpsr_val = get_cpsr0();
myPrint("get_cpsr0", cpsr_val);
/*
Serial.print("Calling the assembly program isEqual()\n");
resFlag = isEqual(11, 11);
myPrint("isEqual", (int)resFlag);
Serial.print("Calling the assembly program isNegative()\n");
resFlag = isNegative(+10);
myPrint("isNegative", (int)resFlag);
Serial.print("Calling the assembly program getMinSigned()\n");
uResVal = getMinSigned(1, -2, -3, -4); // With four parameters
// Since uResVal size and int size are not different, no changes done to its contents
// Before passing it to the myPrint function which prints the values
myPrint("getMinSigned", (int)uResVal);
Serial.print("Calling the assembly program getMaxUnsigned()\n");
// The below negative values are treated as higher positive values
// 0xFFFF FFFF, 0xFFFF FFFE, 0xFFFF FFFD, 0xFFFF FFFE
// With four parameters
resVal = getMaxUnsigned((unsigned)1, (unsigned)2, (unsigned)3, (unsigned)-4);
myPrint("getMaxUnsigned", resVal);
*/
} // end of loop()
void myPrint(char* fnName, int printVal){
Serial.print("The value returned from the assembly fn ");
Serial.print(fnName);
Serial.print(" : "); Serial.println(printVal);
Serial.print("The value returned from the assembly fn ");
Serial.print(fnName);
Serial.print(" in Hex: 0x"); Serial.println(printVal, HEX);
} // myPrint(char*, int)