Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Friday, September 1, 2023

Assending order of ALP model of 8086 processor


  ORG 100h        ; Origin at 100h

MOV SI, OFFSET NUMBERS ; SI points to the array of numbers
MOV CX, 5       ; Number of elements to sort (change as needed)

SORT_LOOP:
    MOV BX, CX      ; Inner loop counter
    DEC BX          ; Decrement BX since we compare BX with BX+1

INNER_LOOP:
    MOV AX, [SI]    ; Load the value at SI into AX
    CMP AX, [SI+2]  ; Compare with the next value
    JLE NO_SWAP     ; Jump if less than or equal (no swap needed)

    ; Swap the values
    XCHG AX, [SI+2]
    MOV [SI], AX

NO_SWAP:
    ADD SI, 2       ; Move to the next element
    LOOP INNER_LOOP ; Repeat for all elements

    DEC CX          ; Decrement outer loop counter
    LOOP SORT_LOOP  ; Repeat for all elements

   

NUMBERS DB 23, 11, 56, 7, 34 ; Array of numbers to sort

END