jle instruction failed to jump properly

16 Views Asked by At

I am writing a bubble sort algorithm, and here is my code, using AT&T format, x86-64.

.section .data
values:
    .int 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
.section .text
.globl _start
_start:
    movl $values, %esi
    movl $9, %ebx
    movl $9, %ecx
loop:
    movl (%esi), %eax
    cmpl %eax, 4(%esi)
    jle skip
    xchg %eax, 4(%esi)
    movl %eax, (%esi)
skip:
    add $4, %esi
    dec %ebx
    jnz loop
    dec %ecx
    jz end

    movl $values, %esi
    movl %ecx, %ebx
    jmp loop
end:
    movl $1, %eax
    movl $0, %ebx
    int $0x80

I expected the sorting direction to be small to large, but the actual result is from large to small, and when executed to:

    cmpl %eax, 4(%esi)
    jle skip

%eax is 1, 4(%esi) is 2, the jle instruction did not jump

Can someone tell me the answer? Thank you

0

There are 0 best solutions below