bblsortc.s |
| .text .globl bubblesort bubblesort: pushl %ebp movl %esp, %ebp pushl %ebx next_pass: movl $1, -8(%ebp) # sorted = true leal 12(%ebp), %eax # the array size decl (%eax) # n = n - 1 movl $0, -16(%ebp) # i = 0 test: movl -16(%ebp), %eax # x[i] : the array address cmpl 12(%ebp), %eax # x[n] == x[i] jl pass # not equal then more to do # equal then check loop again cmpl $0, -8(%ebp) # are they sorted? je next_pass # equal, then no loop again jmp done # not equal, then done, go home pass: imull $4, -16(%ebp), %ebx # ebx = i*4 : sets ebx to required address movl 8(%ebp), %ecx # move base pointer + 8 to ecx # this is base + 2 elements movl (%ecx,%ebx), %eax cmpl 12(%ebp), %eax jle increment swap: movl %eax, -20(%ebp) # put value in acc into address speced here movl %ebx, %eax # eax = ebx = i*4 addl 8(%ebp), %eax # eax = ebx = i*4 + 8 movl %eax, %edx # edx can do eax thing so we don't have to reload eax addl $4, %edx # increment up 4 movl (%edx), %edx # take value from edx movl %edx, (%ecx,%ebx) # and put it in this address... section:offset? leal 4(%eax), %edx # load edx with an address movl -20(%ebp), %eax # take value out again movl %eax, (%edx) # put it here movl $0, -8(%ebp) # sorted = flase increment: leal -16(%ebp), %eax # decrement n incl (%eax) jmp test # try again done: leave # reset ret # return |
James Little |