%macro print 2  ;macro for printing the o/p
    mov rax,1
    mov rdi,1
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

section .data
    array db 22h,0a0h,82h,19h,0ffh
    count db 5
    msg1 db "The sorted array in descending order is as follows:  ",10
    msg1len equ $-msg1

section .bss
    result resb 20
    temp resb 2

section .text
    global _start

_start:
    print msg1,msg1len
;sorting the array
    call loop1
;displaying the array
    mov esi,array
    mov edi,result
    showloop:
        mov bp,2
        mov al,[esi]
        up1:
            rol al,4
            mov bl,al
            and al,0fh
            cmp al,09h
            jbe down
            add al,07h
        down: 
            add al,30h
            mov byte[edi],al
            mov al,bl
            inc edi
            dec bp
            jnz up1
        mov byte[edi],","
        inc edi
        inc esi
        dec byte[count]
        jnz showloop

    print result,20             ;--sorted array in form of string--
    
    mov rax, 60               ;exit sequence
    mov rdi, 0
    syscall               

;Sorting logic
loop1:
    mov bx,4 ;outer loop counter
again:
    mov esi,array           ;initialize the pointer to the first element of the array
    mov cx,4    ;jmp up(set the counter to 4 iterations)
    up:
        mov al,byte[esi]            ;move the first element in AL register 
        cmp al,byte[esi+1]
        jae skip                ;jae will sort in descending order and jbe will sort in ascending order
        xchg al,[esi+1]
        mov [esi],al
    skip:
        inc esi                     ;increment the pointer to the next location
        dec cx          ;decrement the inner loop counter(we have already completed one iteration)
        jnz up
    dec bx      ;decrement the outer loop counter
    jnz again
ret

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: