Sam Vilmenay / Mbed 2 deprecated AssemblySort

Dependencies:   mbed

main.cpp

Committer:
samvilm
Date:
2020-01-04
Revision:
2:968db132481b
Parent:
0:fb6bbc10ffa0

File content as of revision 2:968db132481b:

 #include "mbed.h"
// Function prototypes
extern "C" int asm_sort(int numbers[16], int size);
extern "C" int my_leds(int value);

void c_sort (int numbers[16], int size){
  int temp;
    for (int out_count = 0; out_count <= size - 2; out_count++){
        for (int in_count = 0; in_count <= size - 2 - out_count; in_count++){
            if (numbers[in_count] > numbers[in_count + 1]){
                temp = numbers[in_count];
                numbers[in_count] = numbers[in_count + 1];
                numbers[in_count + 1] = temp;
            }
        }
    }
}

// Declare LED outputs
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
// Set up array to sort
const int size = 16;
int numbers[size] = {12, 11, 14, 10, 9, 8, 22, 7, 6, 5, 15, 4, 3, 2, 0, 1};

int main() {
   // Show current array contents and set lights to "before" pattern
   
    printf("Before\n\r");
    for(int index = 0; index <= size-1; index++){
        printf("%d, ", numbers[index]);
        my_leds(numbers[index]);
        wait(0.5);
    }
    
   // Call the sort function, comment out the one not being used
   asm_sort(numbers, size);  // Call to assembly sort
   //c_sort(numbers, size);  // Call to driver test stub
   
   printf("\n\rAfter\n\r");
   
    for(int index = 0; index <= size-1; index++){
        printf("%d, ", numbers[index]);
        my_leds(numbers[index]);
        wait(0.5);
    }
      
    while(1) {} 
}