650610155 BUBLE SORT HW
650610155 BUBLE SORT HW
650610155 BUBLE SORT HW
LDI R16,0x03
ST X+, r16
INC R17
LDI R16,0x02
ST X+, r16
INC R17
LDI R16,0x04
ST X+, r16
INC R17
LDI R16,0x01
ST X+, r16 ; store in SRAM (the last member of array)
INC R17
call BUBBLE_SORT
;--------------------------------------------
END: jmp END
;====================================================
;input SRAM ADDR 0x100 to 0x104, R17 (array size variable)
;output SRAM ADDR 0x100 to 0x104
;resource R18, R19, R20, R26, R27
BUBBLE_SORT:
MOV R18, R17 ; Outer loop counter initialization
DEC R18 ; R18 = array size - 1 (since we compare pairs)
OUTER_LOOP:
MOV R19, R18 ; Copy outer loop counter to inner loop counter
INNER_LOOP:
LD R0, X ; Load value at current position
LD R1, X+ ; Load next value
NO_SWAP:
DEC R19 ; Decrement inner loop counter
BRNE INNER_LOOP ; If not zero, repeat inner loop
;====================================================