20155231 第八周 课下作业1
第八周课下作业1
- 完成家庭作业4.47,4.48,4.49
- 相应代码反汇编成X86-64汇编
- 把上述X86-64汇编翻译成Y86汇编,并给出相应机器码
4.47
- A、书写一个C版本的冒泡排序法,用指针引用数组元素,而不是数组索引。
- B、书写并测试一个由这个函数和测试代码组成的Y86-64程序。
汇编代码:
.file "4.47.c"
.text
.globl a
.type a, @function
a:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -24(%rbp)
movl %esi, -28(%rbp)
movl $1, -8(%rbp)
jmp .L2
.L6:
movl -8(%rbp), %eax
subl $1, %eax
movl %eax, -12(%rbp)
jmp .L3
.L5:
movl -12(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %edx
movl -12(%rbp), %eax
cltq
leaq 0(,%rax,4), %rcx
movq -24(%rbp), %rax
addq %rcx, %rax
movl (%rax), %eax
cmpl %eax, %edx
jge .L4
movl -12(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
movl %eax, -4(%rbp)
movl -12(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -12(%rbp), %eax
cltq
leaq 0(,%rax,4), %rcx
movq -24(%rbp), %rax
addq %rcx, %rax
movl (%rax), %eax
movl %eax, (%rdx)
movl -12(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -4(%rbp), %eax
movl %eax, (%rdx)
.L4:
subl $1, -12(%rbp)
.L3:
cmpl $0, -12(%rbp)
jns .L5
addl $1, -8(%rbp)
.L2:
movl -8(%rbp), %eax
cmpl -28(%rbp), %eax
jl .L6
nop
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size a, .-a
.section .rodata
.LC0:
.string "%2d"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movl $4, -32(%rbp)
movl $3, -28(%rbp)
movl $2, -24(%rbp)
movl $1, -20(%rbp)
movl $0, -16(%rbp)
leaq -32(%rbp), %rax
movl $5, %esi
movq %rax, %rdi
call a
movl $0, -36(%rbp)
jmp .L8
.L9:
movl -36(%rbp), %eax
cltq
movl -32(%rbp,%rax,4), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
addl $1, -36(%rbp)
.L8:
cmpl $4, -36(%rbp)
jle .L9
nop
movq -8(%rbp), %rax
xorq %fs:40, %rax
je .L10
call __stack_chk_fail
.L10:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413"
.section .note.GNU-stack,"",@progbits
机器码:
4.47.o: 文件格式 elf64-x86-64
Disassembly of section .init:
0000000000400428 <_init>:
400428: 48 83 ec 08 sub $0x8,%rsp
40042c: 48 8b 05 c5 0b 20 00 mov 0x200bc5(%rip),%rax # 600ff8 <_DYNAMIC+0x1d0>
400433: 48 85 c0 test %rax,%rax
400436: 74 05 je 40043d <_init+0x15>
400438: e8 53 00 00 00 callq 400490 <__libc_start_main@plt+0x10>
40043d: 48 83 c4 08 add $0x8,%rsp
400441: c3 retq
Disassembly of section .plt:
0000000000400450 <__stack_chk_fail@plt-0x10>:
400450: ff 35 b2 0b 20 00 pushq 0x200bb2(%rip) # 601008 <_GLOBAL_OFFSET_TABLE_+0x8>
400456: ff 25 b4 0b 20 00 jmpq *0x200bb4(%rip) # 601010 <_GLOBAL_OFFSET_TABLE_+0x10>
40045c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400460 <__stack_chk_fail@plt>:
400460: ff 25 b2 0b 20 00 jmpq *0x200bb2(%rip) # 601018 <_GLOBAL_OFFSET_TABLE_+0x18>
400466: 68 00 00 00 00 pushq $0x0
40046b: e9 e0 ff ff ff jmpq 400450 <_init+0x28>
0000000000400470 <printf@plt>:
400470: ff 25 aa 0b 20 00 jmpq *0x200baa(%rip) # 601020 <_GLOBAL_OFFSET_TABLE_+0x20>
400476: 68 01 00 00 00 pushq $0x1
40047b: e9 d0 ff ff ff jmpq 400450 <_init+0x28>
0000000000400480 <__libc_start_main@plt>:
400480: ff 25 a2 0b 20 00 jmpq *0x200ba2(%rip) # 601028 <_GLOBAL_OFFSET_TABLE_+0x28>
400486: 68 02 00 00 00 pushq $0x2
40048b: e9 c0 ff ff ff jmpq 400450 <_init+0x28>
Disassembly of section .plt.got:
0000000000400490 <.plt.got>:
400490: ff 25 62 0b 20 00 jmpq *0x200b62(%rip) # 600ff8 <_DYNAMIC+0x1d0>
400496: 66 90 xchg %ax,%ax
Disassembly of section .text:
00000000004004a0 <_start>:
4004a0: 31 ed xor %ebp,%ebp
4004a2: 49 89 d1 mov %rdx,%r9
4004a5: 5e pop %rsi
4004a6: 48 89 e2 mov %rsp,%rdx
4004a9: 48 83 e4 f0 and $0xfffffffffffffff0,%rsp
4004ad: 50 push %rax
4004ae: 54 push %rsp
4004af: 49 c7 c0 80 07 40 00 mov $0x400780,%r8
4004b6: 48 c7 c1 10 07 40 00 mov $0x400710,%rcx
4004bd: 48 c7 c7 76 06 40 00 mov $0x400676,%rdi
4004c4: e8 b7 ff ff ff callq 400480 <__libc_start_main@plt>
4004c9: f4 hlt
4004ca: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
00000000004004d0 <deregister_tm_clones>:
4004d0: b8 47 10 60 00 mov $0x601047,%eax
4004d5: 55 push %rbp
4004d6: 48 2d 40 10 60 00 sub $0x601040,%rax
4004dc: 48 83 f8 0e cmp $0xe,%rax
4004e0: 48 89 e5 mov %rsp,%rbp
4004e3: 76 1b jbe 400500 <deregister_tm_clones+0x30>
4004e5: b8 00 00 00 00 mov $0x0,%eax
4004ea: 48 85 c0 test %rax,%rax
4004ed: 74 11 je 400500 <deregister_tm_clones+0x30>
4004ef: 5d pop %rbp
4004f0: bf 40 10 60 00 mov $0x601040,%edi
4004f5: ff e0 jmpq *%rax
4004f7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
4004fe: 00 00
400500: 5d pop %rbp
400501: c3 retq
400502: 0f 1f 40 00 nopl 0x0(%rax)
400506: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40050d: 00 00 00
0000000000400510 <register_tm_clones>:
400510: be 40 10 60 00 mov $0x601040,%esi
400515: 55 push %rbp
400516: 48 81 ee 40 10 60 00 sub $0x601040,%rsi
40051d: 48 c1 fe 03 sar $0x3,%rsi
400521: 48 89 e5 mov %rsp,%rbp
400524: 48 89 f0 mov %rsi,%rax
400527: 48 c1 e8 3f shr $0x3f,%rax
40052b: 48 01 c6 add %rax,%rsi
40052e: 48 d1 fe sar %rsi
400531: 74 15 je 400548 <register_tm_clones+0x38>
400533: b8 00 00 00 00 mov $0x0,%eax
400538: 48 85 c0 test %rax,%rax
40053b: 74 0b je 400548 <register_tm_clones+0x38>
40053d: 5d pop %rbp
40053e: bf 40 10 60 00 mov $0x601040,%edi
400543: ff e0 jmpq *%rax
400545: 0f 1f 00 nopl (%rax)
400548: 5d pop %rbp
400549: c3 retq
40054a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
0000000000400550 <__do_global_dtors_aux>:
400550: 80 3d e9 0a 20 00 00 cmpb $0x0,0x200ae9(%rip) # 601040 <__TMC_END__>
400557: 75 11 jne 40056a <__do_global_dtors_aux+0x1a>
400559: 55 push %rbp
40055a: 48 89 e5 mov %rsp,%rbp
40055d: e8 6e ff ff ff callq 4004d0 <deregister_tm_clones>
400562: 5d pop %rbp
400563: c6 05 d6 0a 20 00 01 movb $0x1,0x200ad6(%rip) # 601040 <__TMC_END__>
40056a: f3 c3 repz retq
40056c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400570 <frame_dummy>:
400570: bf 20 0e 60 00 mov $0x600e20,%edi
400575: 48 83 3f 00 cmpq $0x0,(%rdi)
400579: 75 05 jne 400580 <frame_dummy+0x10>
40057b: eb 93 jmp 400510 <register_tm_clones>
40057d: 0f 1f 00 nopl (%rax)
400580: b8 00 00 00 00 mov $0x0,%eax
400585: 48 85 c0 test %rax,%rax
400588: 74 f1 je 40057b <frame_dummy+0xb>
40058a: 55 push %rbp
40058b: 48 89 e5 mov %rsp,%rbp
40058e: ff d0 callq *%rax
400590: 5d pop %rbp
400591: e9 7a ff ff ff jmpq 400510 <register_tm_clones>
0000000000400596 <a>:
400596: 55 push %rbp
400597: 48 89 e5 mov %rsp,%rbp
40059a: 48 89 7d e8 mov %rdi,-0x18(%rbp)
40059e: 89 75 e4 mov %esi,-0x1c(%rbp)
4005a1: c7 45 f8 01 00 00 00 movl $0x1,-0x8(%rbp)
4005a8: e9 ba 00 00 00 jmpq 400667 <a+0xd1>
4005ad: 8b 45 f8 mov -0x8(%rbp),%eax
4005b0: 83 e8 01 sub $0x1,%eax
4005b3: 89 45 f4 mov %eax,-0xc(%rbp)
4005b6: e9 9e 00 00 00 jmpq 400659 <a+0xc3>
4005bb: 8b 45 f4 mov -0xc(%rbp),%eax
4005be: 48 98 cltq
4005c0: 48 83 c0 01 add $0x1,%rax
4005c4: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
4005cb: 00
4005cc: 48 8b 45 e8 mov -0x18(%rbp),%rax
4005d0: 48 01 d0 add %rdx,%rax
4005d3: 8b 10 mov (%rax),%edx
4005d5: 8b 45 f4 mov -0xc(%rbp),%eax
4005d8: 48 98 cltq
4005da: 48 8d 0c 85 00 00 00 lea 0x0(,%rax,4),%rcx
4005e1: 00
4005e2: 48 8b 45 e8 mov -0x18(%rbp),%rax
4005e6: 48 01 c8 add %rcx,%rax
4005e9: 8b 00 mov (%rax),%eax
4005eb: 39 c2 cmp %eax,%edx
4005ed: 7d 66 jge 400655 <a+0xbf>
4005ef: 8b 45 f4 mov -0xc(%rbp),%eax
4005f2: 48 98 cltq
4005f4: 48 83 c0 01 add $0x1,%rax
4005f8: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
4005ff: 00
400600: 48 8b 45 e8 mov -0x18(%rbp),%rax
400604: 48 01 d0 add %rdx,%rax
400607: 8b 00 mov (%rax),%eax
400609: 89 45 fc mov %eax,-0x4(%rbp)
40060c: 8b 45 f4 mov -0xc(%rbp),%eax
40060f: 48 98 cltq
400611: 48 83 c0 01 add $0x1,%rax
400615: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
40061c: 00
40061d: 48 8b 45 e8 mov -0x18(%rbp),%rax
400621: 48 01 c2 add %rax,%rdx
400624: 8b 45 f4 mov -0xc(%rbp),%eax
400627: 48 98 cltq
400629: 48 8d 0c 85 00 00 00 lea 0x0(,%rax,4),%rcx
400630: 00
400631: 48 8b 45 e8 mov -0x18(%rbp),%rax
400635: 48 01 c8 add %rcx,%rax
400638: 8b 00 mov (%rax),%eax
40063a: 89 02 mov %eax,(%rdx)
40063c: 8b 45 f4 mov -0xc(%rbp),%eax
40063f: 48 98 cltq
400641: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
400648: 00
400649: 48 8b 45 e8 mov -0x18(%rbp),%rax
40064d: 48 01 c2 add %rax,%rdx
400650: 8b 45 fc mov -0x4(%rbp),%eax
400653: 89 02 mov %eax,(%rdx)
400655: 83 6d f4 01 subl $0x1,-0xc(%rbp)
400659: 83 7d f4 00 cmpl $0x0,-0xc(%rbp)
40065d: 0f 89 58 ff ff ff jns 4005bb <a+0x25>
400663: 83 45 f8 01 addl $0x1,-0x8(%rbp)
400667: 8b 45 f8 mov -0x8(%rbp),%eax
40066a: 3b 45 e4 cmp -0x1c(%rbp),%eax
40066d: 0f 8c 3a ff ff ff jl 4005ad <a+0x17>
400673: 90 nop
400674: 5d pop %rbp
400675: c3 retq
0000000000400676 <main>:
400676: 55 push %rbp
400677: 48 89 e5 mov %rsp,%rbp
40067a: 48 83 ec 30 sub $0x30,%rsp
40067e: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
400685: 00 00
400687: 48 89 45 f8 mov %rax,-0x8(%rbp)
40068b: 31 c0 xor %eax,%eax
40068d: c7 45 e0 04 00 00 00 movl $0x4,-0x20(%rbp)
400694: c7 45 e4 03 00 00 00 movl $0x3,-0x1c(%rbp)
40069b: c7 45 e8 02 00 00 00 movl $0x2,-0x18(%rbp)
4006a2: c7 45 ec 01 00 00 00 movl $0x1,-0x14(%rbp)
4006a9: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%rbp)
4006b0: 48 8d 45 e0 lea -0x20(%rbp),%rax
4006b4: be 05 00 00 00 mov $0x5,%esi
4006b9: 48 89 c7 mov %rax,%rdi
4006bc: e8 d5 fe ff ff callq 400596 <a>
4006c1: c7 45 dc 00 00 00 00 movl $0x0,-0x24(%rbp)
4006c8: eb 1e jmp 4006e8 <main+0x72>
4006ca: 8b 45 dc mov -0x24(%rbp),%eax
4006cd: 48 98 cltq
4006cf: 8b 44 85 e0 mov -0x20(%rbp,%rax,4),%eax
4006d3: 89 c6 mov %eax,%esi
4006d5: bf 94 07 40 00 mov $0x400794,%edi
4006da: b8 00 00 00 00 mov $0x0,%eax
4006df: e8 8c fd ff ff callq 400470 <printf@plt>
4006e4: 83 45 dc 01 addl $0x1,-0x24(%rbp)
4006e8: 83 7d dc 04 cmpl $0x4,-0x24(%rbp)
4006ec: 7e dc jle 4006ca <main+0x54>
4006ee: 90 nop
4006ef: 48 8b 45 f8 mov -0x8(%rbp),%rax
4006f3: 64 48 33 04 25 28 00 xor %fs:0x28,%rax
4006fa: 00 00
4006fc: 74 05 je 400703 <main+0x8d>
4006fe: e8 5d fd ff ff callq 400460 <__stack_chk_fail@plt>
400703: c9 leaveq
400704: c3 retq
400705: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40070c: 00 00 00
40070f: 90 nop
0000000000400710 <__libc_csu_init>:
400710: 41 57 push %r15
400712: 41 56 push %r14
400714: 41 89 ff mov %edi,%r15d
400717: 41 55 push %r13
400719: 41 54 push %r12
40071b: 4c 8d 25 ee 06 20 00 lea 0x2006ee(%rip),%r12 # 600e10 <__frame_dummy_init_array_entry>
400722: 55 push %rbp
400723: 48 8d 2d ee 06 20 00 lea 0x2006ee(%rip),%rbp # 600e18 <__init_array_end>
40072a: 53 push %rbx
40072b: 49 89 f6 mov %rsi,%r14
40072e: 49 89 d5 mov %rdx,%r13
400731: 4c 29 e5 sub %r12,%rbp
400734: 48 83 ec 08 sub $0x8,%rsp
400738: 48 c1 fd 03 sar $0x3,%rbp
40073c: e8 e7 fc ff ff callq 400428 <_init>
400741: 48 85 ed test %rbp,%rbp
400744: 74 20 je 400766 <__libc_csu_init+0x56>
400746: 31 db xor %ebx,%ebx
400748: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
40074f: 00
400750: 4c 89 ea mov %r13,%rdx
400753: 4c 89 f6 mov %r14,%rsi
400756: 44 89 ff mov %r15d,%edi
400759: 41 ff 14 dc callq *(%r12,%rbx,8)
40075d: 48 83 c3 01 add $0x1,%rbx
400761: 48 39 eb cmp %rbp,%rbx
400764: 75 ea jne 400750 <__libc_csu_init+0x40>
400766: 48 83 c4 08 add $0x8,%rsp
40076a: 5b pop %rbx
40076b: 5d pop %rbp
40076c: 41 5c pop %r12
40076e: 41 5d pop %r13
400770: 41 5e pop %r14
400772: 41 5f pop %r15
400774: c3 retq
400775: 90 nop
400776: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40077d: 00 00 00
0000000000400780 <__libc_csu_fini>:
400780: f3 c3 repz retq
Disassembly of section .fini:
0000000000400784 <_fini>:
400784: 48 83 ec 08 sub $0x8,%rsp
400788: 48 83 c4 08 add $0x8,%rsp
40078c: c3 retq
Y86:
c:
.LFB22:
.cfi_startproc
pushl %edi
.cfi_def_cfa_offset 8
.cfi_offset 7, -8
pushl %esi
.cfi_def_cfa_offset 12
.cfi_offset 6, -12
pushl %ebx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
mrmovl 16(%esp), %edx
mrmovl 20(%esp), %edi
irmovl $1, %eax
subl %eax, %edi
jle .L1
subl $1, %edi
irmovl $0, %esi
.L6:
rrmovl %esi, %eax
irmovl $0 , ebx
subl %ebx, %esi
jl .L3
.L7:
rrmovl %eax, %ecx
addl %ecx, %ecx
addl %ecx, %ecx
addl %edx, %ecx
mrmovl 4(%ecx), %ecx
rrmovl %eax, %ebx
addl %ecx, %ebx
addl %ecx, %ebx
addl %edx, %ebx
mrmovl (%ebx), %ebx
subl %ebx, %ecx
jge .L4
addl %eax, %eax
addl %eax, %eax
addl %edx, %eax
rmmovl %ebx, 4(%eax)
addl %eax, %eax
addl %eax, %eax
addl %edx, %eax
rmmovl %ecx, 4(%eax)
.L4:
subl $1, %eax
irmovl $-1, %edx
subl %edx, %eax
jne .L7
.L3:
addl $1, %esi
subl %edi, %esi
jne .L6
.L1:
popl %ebx
.cfi_def_cfa_offset 12
.cfi_restore 3
popl %esi
.cfi_def_cfa_offset 8
.cfi_restore 6
popl %edi
.cfi_def_cfa_offset 4
.cfi_restore 7
ret
.cfi_endproc
.LFE22:
.size bubble_c, .-bubble_c
.section .rodata.str1.1,"aMS",@progbits,1
4.48
实现冒泡排序,要求不使用跳转,且最多使用3次条件传送。
汇编代码:
.file "4.48.c"
.text
.globl c
.type c, @function
c:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -24(%rbp)
movl %esi, -28(%rbp)
movl $1, -12(%rbp)
jmp .L2
.L5:
movl -12(%rbp), %eax
subl $1, %eax
movl %eax, -16(%rbp)
jmp .L3
.L4:
movl -16(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
movl %eax, -8(%rbp)
movl -16(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
movl %eax, -4(%rbp)
movl -16(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -4(%rbp), %eax
cmpl %eax, -8(%rbp)
cmovle -8(%rbp), %eax
movl %eax, (%rdx)
movl -16(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -8(%rbp), %eax
cmpl %eax, -4(%rbp)
cmovge -4(%rbp), %eax
movl %eax, (%rdx)
subl $1, -16(%rbp)
.L3:
cmpl $0, -16(%rbp)
jns .L4
addl $1, -12(%rbp)
.L2:
movl -12(%rbp), %eax
cmpl -28(%rbp), %eax
jl .L5
nop
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size c, .-c
.section .rodata
.LC0:
.string "%2d"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movl $4, -32(%rbp)
movl $3, -28(%rbp)
movl $2, -24(%rbp)
movl $1, -20(%rbp)
movl $0, -16(%rbp)
leaq -32(%rbp), %rax
movl $5, %esi
movq %rax, %rdi
call c
movl $0, -36(%rbp)
jmp .L7
.L8:
movl -36(%rbp), %eax
cltq
movl -32(%rbp,%rax,4), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
addl $1, -36(%rbp)
.L7:
cmpl $4, -36(%rbp)
jle .L8
nop
movq -8(%rbp), %rax
xorq %fs:40, %rax
je .L9
call __stack_chk_fail
.L9:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413"
.section .note.GNU-stack,"",@progbits
反汇编代码:
.file "4.48.c"
.text
.globl c
.type c, @function
c:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -24(%rbp)
movl %esi, -28(%rbp)
movl $1, -12(%rbp)
jmp .L2
.L5:
movl -12(%rbp), %eax
subl $1, %eax
movl %eax, -16(%rbp)
jmp .L3
.L4:
movl -16(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
movl %eax, -8(%rbp)
movl -16(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
movl %eax, -4(%rbp)
movl -16(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -4(%rbp), %eax
cmpl %eax, -8(%rbp)
cmovle -8(%rbp), %eax
movl %eax, (%rdx)
movl -16(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -8(%rbp), %eax
cmpl %eax, -4(%rbp)
cmovge -4(%rbp), %eax
movl %eax, (%rdx)
subl $1, -16(%rbp)
.L3:
cmpl $0, -16(%rbp)
jns .L4
addl $1, -12(%rbp)
.L2:
movl -12(%rbp), %eax
cmpl -28(%rbp), %eax
jl .L5
nop
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size c, .-c
.section .rodata
.LC0:
.string "%2d"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movl $4, -32(%rbp)
movl $3, -28(%rbp)
movl $2, -24(%rbp)
movl $1, -20(%rbp)
movl $0, -16(%rbp)
leaq -32(%rbp), %rax
movl $5, %esi
movq %rax, %rdi
call c
movl $0, -36(%rbp)
jmp .L7
.L8:
movl -36(%rbp), %eax
cltq
movl -32(%rbp,%rax,4), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
addl $1, -36(%rbp)
.L7:
cmpl $4, -36(%rbp)
jle .L8
nop
movq -8(%rbp), %rax
xorq %fs:40, %rax
je .L9
call __stack_chk_fail
.L9:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413"
.section .note.GNU-stack,"",@progbits
Y86:
b:
.LFB22:
.cfi_startproc
pushl %edi
.cfi_def_cfa_offset 8
.cfi_offset 7, -8
pushl %esi
.cfi_def_cfa_offset 12
.cfi_offset 6, -12
pushl %ebx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
mrmovl 16(%esp), %edx
mrmovl 20(%esp), %edi
irmovl $1, %eax
subl %eax, %edi
jle .L1
subl $1, %edi
irmovl $0, %esi
.L6:
movl (%ebx,%eax,4), %edx
movl 4(%ebx,%eax,4), %ecx
cmpl %edx, %ecx
movl %edx, %ebp
cmovle %ecx, %ebp
movl %ebp, (%ebx,%eax,4)
cmovge %ecx, %edx
movl %edx, 4(%ebx,%eax,4)
subl $1, %eax
cmpl $-1, %eax
jne .L6
.L7:
rrmovl %eax, %ecx
addl %ecx, %ecx
addl %ecx, %ecx
addl %edx, %ecx
mrmovl 4(%ecx), %ecx
rrmovl %eax, %ebx
addl %ecx, %ebx
addl %ecx, %ebx
addl %edx, %ebx
mrmovl (%ebx), %ebx
subl %ebx, %ecx
jge .L4
addl %eax, %eax
addl %eax, %eax
addl %edx, %eax
rmmovl %ebx, 4(%eax)
addl %eax, %eax
addl %eax, %eax
addl %edx, %eax
rmmovl %ecx, 4(%eax)
.L4:
subl $1, %eax
irmovl $-1, %edx
subl %edx, %eax
jne .L7
.L3:
addl $1, %esi
subl %edi, %esi
jne .L6
.L1:
popl %ebx
.cfi_def_cfa_offset 12
.cfi_restore 3
popl %esi
.cfi_def_cfa_offset 8
.cfi_restore 6
popl %edi
.cfi_def_cfa_offset 4
.cfi_restore 7
ret
.cfi_endproc
.LFE22:
.size bubble_b, .-bubble_b
.section .rodata.str1.1,"aMS",@progbits,1
4.49
实现冒泡排序,要求不使用跳转,且最多使用1次条件传送。
汇编代码:
.file "4.49.c"
.text
.globl b
.type b, @function
b:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -24(%rbp)
movl %esi, -28(%rbp)
movl $1, -12(%rbp)
jmp .L2
.L5:
movl -12(%rbp), %eax
subl $1, %eax
movl %eax, -16(%rbp)
jmp .L3
.L4:
movl -16(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
movl %eax, -8(%rbp)
movl -16(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rdx, %rax
movl (%rax), %eax
movl %eax, -4(%rbp)
movl -16(%rbp), %eax
cltq
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -4(%rbp), %eax
cmpl %eax, -8(%rbp)
cmovle -8(%rbp), %eax
movl %eax, (%rdx)
movl -16(%rbp), %eax
cltq
addq $1, %rax
leaq 0(,%rax,4), %rdx
movq -24(%rbp), %rax
addq %rax, %rdx
movl -8(%rbp), %eax
movl %eax, (%rdx)
subl $1, -16(%rbp)
.L3:
cmpl $0, -16(%rbp)
jns .L4
addl $1, -12(%rbp)
.L2:
movl -12(%rbp), %eax
cmpl -28(%rbp), %eax
jl .L5
nop
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size b, .-b
.section .rodata
.LC0:
.string "%2d"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movl $4, -32(%rbp)
movl $3, -28(%rbp)
movl $2, -24(%rbp)
movl $1, -20(%rbp)
movl $0, -16(%rbp)
leaq -32(%rbp), %rax
movl $5, %esi
movq %rax, %rdi
call b
movl $0, -36(%rbp)
jmp .L7
.L8:
movl -36(%rbp), %eax
cltq
movl -32(%rbp,%rax,4), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
addl $1, -36(%rbp)
.L7:
cmpl $4, -36(%rbp)
jle .L8
nop
movq -8(%rbp), %rax
xorq %fs:40, %rax
je .L9
call __stack_chk_fail
.L9:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413"
.section .note.GNU-stack,"",@progbits
反汇编代码:
4.49.o: 文件格式 elf64-x86-64
Disassembly of section .init:
0000000000400428 <_init>:
400428: 48 83 ec 08 sub $0x8,%rsp
40042c: 48 8b 05 c5 0b 20 00 mov 0x200bc5(%rip),%rax # 600ff8 <_DYNAMIC+0x1d0>
400433: 48 85 c0 test %rax,%rax
400436: 74 05 je 40043d <_init+0x15>
400438: e8 53 00 00 00 callq 400490 <__libc_start_main@plt+0x10>
40043d: 48 83 c4 08 add $0x8,%rsp
400441: c3 retq
Disassembly of section .plt:
0000000000400450 <__stack_chk_fail@plt-0x10>:
400450: ff 35 b2 0b 20 00 pushq 0x200bb2(%rip) # 601008 <_GLOBAL_OFFSET_TABLE_+0x8>
400456: ff 25 b4 0b 20 00 jmpq *0x200bb4(%rip) # 601010 <_GLOBAL_OFFSET_TABLE_+0x10>
40045c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400460 <__stack_chk_fail@plt>:
400460: ff 25 b2 0b 20 00 jmpq *0x200bb2(%rip) # 601018 <_GLOBAL_OFFSET_TABLE_+0x18>
400466: 68 00 00 00 00 pushq $0x0
40046b: e9 e0 ff ff ff jmpq 400450 <_init+0x28>
0000000000400470 <printf@plt>:
400470: ff 25 aa 0b 20 00 jmpq *0x200baa(%rip) # 601020 <_GLOBAL_OFFSET_TABLE_+0x20>
400476: 68 01 00 00 00 pushq $0x1
40047b: e9 d0 ff ff ff jmpq 400450 <_init+0x28>
0000000000400480 <__libc_start_main@plt>:
400480: ff 25 a2 0b 20 00 jmpq *0x200ba2(%rip) # 601028 <_GLOBAL_OFFSET_TABLE_+0x28>
400486: 68 02 00 00 00 pushq $0x2
40048b: e9 c0 ff ff ff jmpq 400450 <_init+0x28>
Disassembly of section .plt.got:
0000000000400490 <.plt.got>:
400490: ff 25 62 0b 20 00 jmpq *0x200b62(%rip) # 600ff8 <_DYNAMIC+0x1d0>
400496: 66 90 xchg %ax,%ax
Disassembly of section .text:
00000000004004a0 <_start>:
4004a0: 31 ed xor %ebp,%ebp
4004a2: 49 89 d1 mov %rdx,%r9
4004a5: 5e pop %rsi
4004a6: 48 89 e2 mov %rsp,%rdx
4004a9: 48 83 e4 f0 and $0xfffffffffffffff0,%rsp
4004ad: 50 push %rax
4004ae: 54 push %rsp
4004af: 49 c7 c0 50 07 40 00 mov $0x400750,%r8
4004b6: 48 c7 c1 e0 06 40 00 mov $0x4006e0,%rcx
4004bd: 48 c7 c7 48 06 40 00 mov $0x400648,%rdi
4004c4: e8 b7 ff ff ff callq 400480 <__libc_start_main@plt>
4004c9: f4 hlt
4004ca: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
00000000004004d0 <deregister_tm_clones>:
4004d0: b8 47 10 60 00 mov $0x601047,%eax
4004d5: 55 push %rbp
4004d6: 48 2d 40 10 60 00 sub $0x601040,%rax
4004dc: 48 83 f8 0e cmp $0xe,%rax
4004e0: 48 89 e5 mov %rsp,%rbp
4004e3: 76 1b jbe 400500 <deregister_tm_clones+0x30>
4004e5: b8 00 00 00 00 mov $0x0,%eax
4004ea: 48 85 c0 test %rax,%rax
4004ed: 74 11 je 400500 <deregister_tm_clones+0x30>
4004ef: 5d pop %rbp
4004f0: bf 40 10 60 00 mov $0x601040,%edi
4004f5: ff e0 jmpq *%rax
4004f7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
4004fe: 00 00
400500: 5d pop %rbp
400501: c3 retq
400502: 0f 1f 40 00 nopl 0x0(%rax)
400506: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40050d: 00 00 00
0000000000400510 <register_tm_clones>:
400510: be 40 10 60 00 mov $0x601040,%esi
400515: 55 push %rbp
400516: 48 81 ee 40 10 60 00 sub $0x601040,%rsi
40051d: 48 c1 fe 03 sar $0x3,%rsi
400521: 48 89 e5 mov %rsp,%rbp
400524: 48 89 f0 mov %rsi,%rax
400527: 48 c1 e8 3f shr $0x3f,%rax
40052b: 48 01 c6 add %rax,%rsi
40052e: 48 d1 fe sar %rsi
400531: 74 15 je 400548 <register_tm_clones+0x38>
400533: b8 00 00 00 00 mov $0x0,%eax
400538: 48 85 c0 test %rax,%rax
40053b: 74 0b je 400548 <register_tm_clones+0x38>
40053d: 5d pop %rbp
40053e: bf 40 10 60 00 mov $0x601040,%edi
400543: ff e0 jmpq *%rax
400545: 0f 1f 00 nopl (%rax)
400548: 5d pop %rbp
400549: c3 retq
40054a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
0000000000400550 <__do_global_dtors_aux>:
400550: 80 3d e9 0a 20 00 00 cmpb $0x0,0x200ae9(%rip) # 601040 <__TMC_END__>
400557: 75 11 jne 40056a <__do_global_dtors_aux+0x1a>
400559: 55 push %rbp
40055a: 48 89 e5 mov %rsp,%rbp
40055d: e8 6e ff ff ff callq 4004d0 <deregister_tm_clones>
400562: 5d pop %rbp
400563: c6 05 d6 0a 20 00 01 movb $0x1,0x200ad6(%rip) # 601040 <__TMC_END__>
40056a: f3 c3 repz retq
40056c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000400570 <frame_dummy>:
400570: bf 20 0e 60 00 mov $0x600e20,%edi
400575: 48 83 3f 00 cmpq $0x0,(%rdi)
400579: 75 05 jne 400580 <frame_dummy+0x10>
40057b: eb 93 jmp 400510 <register_tm_clones>
40057d: 0f 1f 00 nopl (%rax)
400580: b8 00 00 00 00 mov $0x0,%eax
400585: 48 85 c0 test %rax,%rax
400588: 74 f1 je 40057b <frame_dummy+0xb>
40058a: 55 push %rbp
40058b: 48 89 e5 mov %rsp,%rbp
40058e: ff d0 callq *%rax
400590: 5d pop %rbp
400591: e9 7a ff ff ff jmpq 400510 <register_tm_clones>
0000000000400596 <b>:
400596: 55 push %rbp
400597: 48 89 e5 mov %rsp,%rbp
40059a: 48 89 7d e8 mov %rdi,-0x18(%rbp)
40059e: 89 75 e4 mov %esi,-0x1c(%rbp)
4005a1: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%rbp)
4005a8: e9 8c 00 00 00 jmpq 400639 <b+0xa3>
4005ad: 8b 45 f4 mov -0xc(%rbp),%eax
4005b0: 83 e8 01 sub $0x1,%eax
4005b3: 89 45 f0 mov %eax,-0x10(%rbp)
4005b6: eb 77 jmp 40062f <b+0x99>
4005b8: 8b 45 f0 mov -0x10(%rbp),%eax
4005bb: 48 98 cltq
4005bd: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
4005c4: 00
4005c5: 48 8b 45 e8 mov -0x18(%rbp),%rax
4005c9: 48 01 d0 add %rdx,%rax
4005cc: 8b 00 mov (%rax),%eax
4005ce: 89 45 f8 mov %eax,-0x8(%rbp)
4005d1: 8b 45 f0 mov -0x10(%rbp),%eax
4005d4: 48 98 cltq
4005d6: 48 83 c0 01 add $0x1,%rax
4005da: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
4005e1: 00
4005e2: 48 8b 45 e8 mov -0x18(%rbp),%rax
4005e6: 48 01 d0 add %rdx,%rax
4005e9: 8b 00 mov (%rax),%eax
4005eb: 89 45 fc mov %eax,-0x4(%rbp)
4005ee: 8b 45 f0 mov -0x10(%rbp),%eax
4005f1: 48 98 cltq
4005f3: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
4005fa: 00
4005fb: 48 8b 45 e8 mov -0x18(%rbp),%rax
4005ff: 48 01 c2 add %rax,%rdx
400602: 8b 45 fc mov -0x4(%rbp),%eax
400605: 39 45 f8 cmp %eax,-0x8(%rbp)
400608: 0f 4e 45 f8 cmovle -0x8(%rbp),%eax
40060c: 89 02 mov %eax,(%rdx)
40060e: 8b 45 f0 mov -0x10(%rbp),%eax
400611: 48 98 cltq
400613: 48 83 c0 01 add $0x1,%rax
400617: 48 8d 14 85 00 00 00 lea 0x0(,%rax,4),%rdx
40061e: 00
40061f: 48 8b 45 e8 mov -0x18(%rbp),%rax
400623: 48 01 c2 add %rax,%rdx
400626: 8b 45 f8 mov -0x8(%rbp),%eax
400629: 89 02 mov %eax,(%rdx)
40062b: 83 6d f0 01 subl $0x1,-0x10(%rbp)
40062f: 83 7d f0 00 cmpl $0x0,-0x10(%rbp)
400633: 79 83 jns 4005b8 <b+0x22>
400635: 83 45 f4 01 addl $0x1,-0xc(%rbp)
400639: 8b 45 f4 mov -0xc(%rbp),%eax
40063c: 3b 45 e4 cmp -0x1c(%rbp),%eax
40063f: 0f 8c 68 ff ff ff jl 4005ad <b+0x17>
400645: 90 nop
400646: 5d pop %rbp
400647: c3 retq
0000000000400648 <main>:
400648: 55 push %rbp
400649: 48 89 e5 mov %rsp,%rbp
40064c: 48 83 ec 30 sub $0x30,%rsp
400650: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax
400657: 00 00
400659: 48 89 45 f8 mov %rax,-0x8(%rbp)
40065d: 31 c0 xor %eax,%eax
40065f: c7 45 e0 04 00 00 00 movl $0x4,-0x20(%rbp)
400666: c7 45 e4 03 00 00 00 movl $0x3,-0x1c(%rbp)
40066d: c7 45 e8 02 00 00 00 movl $0x2,-0x18(%rbp)
400674: c7 45 ec 01 00 00 00 movl $0x1,-0x14(%rbp)
40067b: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%rbp)
400682: 48 8d 45 e0 lea -0x20(%rbp),%rax
400686: be 05 00 00 00 mov $0x5,%esi
40068b: 48 89 c7 mov %rax,%rdi
40068e: e8 03 ff ff ff callq 400596 <b>
400693: c7 45 dc 00 00 00 00 movl $0x0,-0x24(%rbp)
40069a: eb 1e jmp 4006ba <main+0x72>
40069c: 8b 45 dc mov -0x24(%rbp),%eax
40069f: 48 98 cltq
4006a1: 8b 44 85 e0 mov -0x20(%rbp,%rax,4),%eax
4006a5: 89 c6 mov %eax,%esi
4006a7: bf 64 07 40 00 mov $0x400764,%edi
4006ac: b8 00 00 00 00 mov $0x0,%eax
4006b1: e8 ba fd ff ff callq 400470 <printf@plt>
4006b6: 83 45 dc 01 addl $0x1,-0x24(%rbp)
4006ba: 83 7d dc 04 cmpl $0x4,-0x24(%rbp)
4006be: 7e dc jle 40069c <main+0x54>
4006c0: 90 nop
4006c1: 48 8b 45 f8 mov -0x8(%rbp),%rax
4006c5: 64 48 33 04 25 28 00 xor %fs:0x28,%rax
4006cc: 00 00
4006ce: 74 05 je 4006d5 <main+0x8d>
4006d0: e8 8b fd ff ff callq 400460 <__stack_chk_fail@plt>
4006d5: c9 leaveq
4006d6: c3 retq
4006d7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
4006de: 00 00
00000000004006e0 <__libc_csu_init>:
4006e0: 41 57 push %r15
4006e2: 41 56 push %r14
4006e4: 41 89 ff mov %edi,%r15d
4006e7: 41 55 push %r13
4006e9: 41 54 push %r12
4006eb: 4c 8d 25 1e 07 20 00 lea 0x20071e(%rip),%r12 # 600e10 <__frame_dummy_init_array_entry>
4006f2: 55 push %rbp
4006f3: 48 8d 2d 1e 07 20 00 lea 0x20071e(%rip),%rbp # 600e18 <__init_array_end>
4006fa: 53 push %rbx
4006fb: 49 89 f6 mov %rsi,%r14
4006fe: 49 89 d5 mov %rdx,%r13
400701: 4c 29 e5 sub %r12,%rbp
400704: 48 83 ec 08 sub $0x8,%rsp
400708: 48 c1 fd 03 sar $0x3,%rbp
40070c: e8 17 fd ff ff callq 400428 <_init>
400711: 48 85 ed test %rbp,%rbp
400714: 74 20 je 400736 <__libc_csu_init+0x56>
400716: 31 db xor %ebx,%ebx
400718: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
40071f: 00
400720: 4c 89 ea mov %r13,%rdx
400723: 4c 89 f6 mov %r14,%rsi
400726: 44 89 ff mov %r15d,%edi
400729: 41 ff 14 dc callq *(%r12,%rbx,8)
40072d: 48 83 c3 01 add $0x1,%rbx
400731: 48 39 eb cmp %rbp,%rbx
400734: 75 ea jne 400720 <__libc_csu_init+0x40>
400736: 48 83 c4 08 add $0x8,%rsp
40073a: 5b pop %rbx
40073b: 5d pop %rbp
40073c: 41 5c pop %r12
40073e: 41 5d pop %r13
400740: 41 5e pop %r14
400742: 41 5f pop %r15
400744: c3 retq
400745: 90 nop
400746: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40074d: 00 00 00
0000000000400750 <__libc_csu_fini>:
400750: f3 c3 repz retq
Disassembly of section .fini:
0000000000400754 <_fini>:
400754: 48 83 ec 08 sub $0x8,%rsp
400758: 48 83 c4 08 add $0x8,%rsp
40075c: c3 retq
Y86:
b:
.LFB22:
.cfi_startproc
pushl %edi
.cfi_def_cfa_offset 8
.cfi_offset 7, -8
pushl %esi
.cfi_def_cfa_offset 12
.cfi_offset 6, -12
pushl %ebx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
mrmovl 16(%esp), %edx
mrmovl 20(%esp), %edi
irmovl $1, %eax
subl %eax, %edi
jle .L1
subl $1, %edi
irmovl $0, %esi
.L6:
movl (%ebx,%eax,4), %edx
movl 4(%ebx,%eax,4), %ecx
cmpl %edx, %ecx
movl %edx, %ebp
cmovle %ecx, %ebp
movl %edx, 4(%ebx,%eax,4)
subl $1, %eax
cmpl $-1, %eax
jne .L6
.L7:
rrmovl %eax, %ecx
addl %ecx, %ecx
addl %ecx, %ecx
addl %edx, %ecx
mrmovl 4(%ecx), %ecx
rrmovl %eax, %ebx
addl %ecx, %ebx
addl %ecx, %ebx
addl %edx, %ebx
mrmovl (%ebx), %ebx
subl %ebx, %ecx
jge .L4
addl %eax, %eax
addl %eax, %eax
addl %edx, %eax
rmmovl %ebx, 4(%eax)
addl %eax, %eax
addl %eax, %eax
addl %edx, %eax
rmmovl %ecx, 4(%eax)
.L4:
subl $1, %eax
irmovl $-1, %edx
subl %edx, %eax
jne .L7
.L3:
addl $1, %esi
subl %edi, %esi
jne .L6
.L1:
popl %ebx
.cfi_def_cfa_offset 12
.cfi_restore 3
popl %esi
.cfi_def_cfa_offset 8
.cfi_restore 6
popl %edi
.cfi_def_cfa_offset 4
.cfi_restore 7
ret
.cfi_endproc
.LFE22:
.size bubble_b, .-bubble_b
.section .rodata.str1.1,"aMS",@progbits,1
- 用 命令行编译,打开.s文件显示汇编代码
- 用objdump -d .o文件显示反汇编文件