
Sorting Algorithm

This is a sorting algorithm.   It may be applied to a set of data in order to sort it.    
For comparing various sorts, see compare sorts.  
For other sorting algorithms,   see sorting algorithms,   or:

O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
O(n2) sorts
Bubble sort |
Cocktail sort |
Cocktail sort with shifting bounds |
Comb sort |
Cycle sort |
Gnome sort |
Insertion sort |
Selection sort |
Strand sort
other sorts
Bead sort |
Bogo sort |
Common sorted list |
Composite structures sort |
Custom comparator sort |
Counting sort |
Disjoint sublist sort |
External sort |
Jort sort |
Lexicographical sort |
Natural sorting |
Order by pair comparisons |
Order disjoint list items |
Order two numerical lists |
Object identifier (OID) sort |
Pancake sort |
Quickselect |
Permutation sort |
Radix sort |
Ranking methods |
Remove duplicate elements |
Sleep sort |
Stooge sort |
[Sort letters of a string] |
Three variable sort |
Topological sort |
Tree sort




 Note:   jortSort is considered a work of satire.   It achieves its result in an intentionally roundabout way.   You are encouraged to write your solutions in the spirit of the original jortsort rather than trying to give the most concise or idiomatic solution.



JortSort is a sorting tool set that makes the user do the work and guarantees efficiency because you don't have to sort ever again.

It was originally presented by Jenn "Moneydollars" Schiffer at the
prestigious   JSConf.



JortSort is a function that takes a single array of comparable objects as its argument.

It then sorts the array in ascending order and compares the sorted array to the originally provided array.

If the arrays match   (i.e. the original array was already sorted),   the function returns   true.

If the arrays do not match (i.e. the original array was not sorted), the function returns   false.




 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program jortSort64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
szMessOk:         .asciz "Ok, the list is sorted. \n"
szMessNotOk:      .asciz "Ouah!! this list is unsorted.\n"
szCarriageReturn:  .asciz "\n"
tbNumber:           .quad 3
                    .quad 4
                    .quad 20
                    .quad 5
                    .equ LGTBNUMBER, (. - tbNumber)/8  // number element of area 
/*******************************************/
/* UnInitialized data                      */
/*******************************************/
.bss 
sZoneConversion:        .skip 100
.align 4
tbNumberSorted:      .skip 8 * LGTBNUMBER
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main 
main:                             // entry of program
    ldr x0,qAdrtbNumber
    ldr x1,qAdrtbNumberSorted
    mov x2,LGTBNUMBER
    bl insertionSort              // sort area
    ldr x0,qAdrtbNumber
    ldr x1,qAdrtbNumberSorted
    mov x2,LGTBNUMBER
    bl comparArea                // control area
    cbz x0,1f
    ldr x0,qAdrszMessNotOk       // not sorted
    bl affichageMess
    b 100f
1:                               // ok it is good
    ldr x0,qAdrszMessOk
    bl affichageMess
100:                             // standard end of the program
    mov x0, #0                   // return code
    mov x8, #EXIT                // request to exit program
    svc 0                        // perform the system call
 
qAdrtbNumber:          .quad tbNumber
qAdrtbNumberSorted:    .quad tbNumberSorted
qAdrszMessNotOk:       .quad szMessNotOk
qAdrszMessOk:          .quad szMessOk
qAdrszCarriageReturn:  .quad szCarriageReturn
/******************************************************************/
/*     insertion sort                                             */ 
/******************************************************************/
/* x0 contains the address of area to sort  */
/* x1 contains the address of area sorted   */
/* x2 contains the number of element */
insertionSort:
    stp x1,lr,[sp,-16]!         // save  registers
    stp x2,x3,[sp,-16]!         // save  registers
    mov x3,0
1:                              // copy area unsorted to other area
    ldr x4,[x0,x3,lsl 3]
    str x4,[x1,x3,lsl 3]
    add x3,x3,1
    cmp x3,x2
    blt 1b
 
    mov x3,1                   // and sort area
2:
    ldr x4,[x1,x3,lsl 3]
    subs x5,x3,1
3:
    cbz x5,4f
    ldr x6,[x1,x5,lsl 3]
    cmp x6,x4
    ble 4f
    add x7,x5,1
    str x6,[x1,x7,lsl 3]
    subs x5,x5,1
    b 3b
4:
    add x5,x5,1
    str x4,[x1,x5,lsl 3]
    add x3,x3,1
    cmp x3,x2
    blt 2b
100:
    ldp x2,x3,[sp],16           // restaur  2 registers
    ldp x1,lr,[sp],16           // restaur  2 registers
    ret
/******************************************************************/
/*     Comparaison elements of two areas                          */ 
/******************************************************************/
/* x0 contains the address of area to sort  */
/* x1 contains the address of area sorted   */
/* x2 contains the number of element */
comparArea:
    stp x1,lr,[sp,-16]!         // save  registers
    stp x2,x3,[sp,-16]!         // save  registers
    mov x3,0
1:
    ldr x4,[x0,x3,lsl 3]        // load element area 1
    ldr x5,[x1,x3,lsl 3]        // load element area 2
    cmp x4,x5                   // equal ?
    bne 99f                     // no -> error
    add x3,x3,1                 // yes increment indice
    cmp x3,x2                   // maxi ?
    blt 1b                      // no -> loop
    mov x0,0                    // yes -> it is ok 
    b 100f
99:
    mov x0,1 
100:
    ldp x2,x3,[sp],16           // restaur  2 registers
    ldp x1,lr,[sp],16           // restaur  2 registers
    ret
 
 
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 