Bubble sort assembly language

Viewed 79

unable to read memory to sort out from array. we tried to write simple program to swap R1 and R2 first to check the memory content. but it was not swapping R1 and R2 value. it just show same number as per array without any swap. please check my sample code below and kindly help to advice how to swap R1 and R2 value correctly.so that i can sort it out array in descending order.

c++ code :

#include "stdio.h"

#define M 6  // No. of numbers in array

// Necessary function to enable printf() using semihosting
extern void initialise_monitor_handles(void);

// Functions to be written
extern int bubble_sort(int* arg1, int arg2);

int main(void)
{
    // Necessary function to enable printf() using semihosting
    initialise_monitor_handles();

    int arr[M] = {18, 34, 32, 75, 11, 97};
    int swap,i;  // no. of total swaps

    // Bubble sort with bubble_sort.s
    swap = bubble_sort((int*)arr, (int)M);
    printf("After %d rounds of swap, the array is sorted as: \n{ ", swap);

    for (i=0; i<M; i++)
    {
        printf("%d ", arr[i]);
    }

    printf("}\n");

}

bubble-sort.s code

  .syntax unified
    .cpu cortex-m4
    .fpu softvfp
    .thumb
    .global bubble_sort

@ Start of executable code
.section .text
bubble_sort:
    PUSH {R0-R5,LR}

    BL SUBROUTINE
    MOV  R2,R3
    POP {R0-R5,PC}
    BX LR

SUBROUTINE:

    BX LR
0 Answers
Related