Assembly bubble sort swap

I think I’d use pointers into the current position into the list, instead of an index that needs to be scaled every time you use it:

    mov esi, offset list
    mov edi, esi
    mov eax, [edi]
    mov edx, [edi+4]
    cmp eax, edx
    jle no_swap
    mov [edi+4], eax
    mov [edi], edx
    add edi, 4
    cmp edi, list_end - 4
    jb inner
    add esi, 4
    cmp esi, list_end - 4
    jb top

Leave a Comment