// GCD and square functions, written in assembly for the 2021 HackadayU course
// Raspberry Pi Pico and RP2040 - The Deep Dive
// Alan Reed, 2021

extern "C" uint32_t gcd(uint32_t a, uint32_t b);
extern "C" void square(uint32_t nums[], size_t numcount);

void print_nums(uint32_t nums[], size_t numcount) {
  for(int i = 0; i < numcount; i++) {
    Serial1.print(nums[i]);
    Serial1.print(", ");
  }
  Serial1.println("");
}

void setup() {
  Serial1.begin(115200);
  Serial1.println("GCD test");
  uint32_t num;

  num = gcd(18, 24);
  Serial1.print("Greatest common denominator of 18 and 24: ");
  Serial1.println(num);

  num = gcd(2940, 3150);
  Serial1.print("Greatest common denominator of 2940 and 3150: ");
  Serial1.println(num);

  Serial1.println("");
  Serial1.println("Square test");
  const size_t COUNT = 5;
  // Squares: 4, 9, 49, 441, 1600
  uint32_t numbers[COUNT] = {2, 3, 7, 21, 40};
  Serial1.print("Before squaring: ");
  print_nums(numbers, COUNT);

  square(numbers, COUNT);
  Serial1.print("After squaring: ");
  print_nums(numbers, COUNT);

  const size_t COUNT2 = 7;
  // Squares: 1, 361, 16, 10000, 964324, 15129, 36
  uint32_t numbers2[COUNT2] = {1, 19, 4, 100, 982, 123, 6};
  Serial1.print("Before squaring: ");
  print_nums(numbers2, COUNT2);

  square(numbers2, COUNT2);
  Serial1.print("After squaring: ");
  print_nums(numbers2, COUNT2);
}

void loop() {
}
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT