汇编学习笔记-冒泡排序(xchg指令)

这里主要是为了熟悉xchg指令, 不过在自己写了一遍之后再看例子对跳转指令的使用又有了新的认识,虽然现在还没有看到跳转指令。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.section .data
arr:
.int 15, 13, 14, 19, 10, 18, 16, 17, 11, 12
out:
.asciz "%dn"
endl:
.ascii "n"
.section .text
.globl _start
_start:
movl $arr, %edi
movl $10, %edx
loopi:
dec %edx
movl $0, %edi
jz print
movl $0, %ebx
movl $arr, %edi
loopj:
cmpl %ebx, %edx
je loopi
movl (%edi), %eax
cmpl 4(%edi), %eax
jge swap
jmp contj
swap:
xchg %eax, 4(%edi)
movl %eax, (%edi)
contj:
add $4, %edi
inc %ebx
jmp loopj
print:
cmpl $10, %edi
je end
movl arr(, %edi, 4), %eax
pushl %eax
pushl $out
call printf
addl $8, %esp
inc %edi
jmp print
end:
movl $1, %eax
movl $0, %ebx
int $0x80