Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55507
  • 博文数量: 10
  • 博客积分: 365
  • 博客等级: 一等列兵
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-07 16:28
文章存档

2012年(3)

2011年(7)

分类: C/C++

2011-07-22 09:25:05

 

  1. /*
  2. * C
  3. */
  4. int test(int a, int b)
  5. {
  6.     int c;
  7.     c=a+b;
  8.     return c;
  9. }

  10. int main(void)
  11. {
  12.     int a=10,b=20,c;
  13.     c=test(a,b);
  14.     return 0;
  15. }

 

 

  1. #!!!arm处理器,ADS1.2汇编结果
  2. ** Section #5 '.text' (SHT_PROGBITS) [SHF_ALLOC + SHF_EXECINSTR]
  3. Size : 32 bytes (alignment 4)
  4. test
  5. $a
  6. .text
  7. 0x00000000: e0800001 .... ADD r0,r0,r1
  8. 0x00000004: e1a0f00e .... MOV pc,r14
  9. main
  10. 0x00000008: e52de004 ..-. STR r14,[r13,#-4]!
  11. 0x0000000c: e3a0000a .... MOV r0,#0xa
  12. 0x00000010: e3a01014 .... MOV r1,#0x14
  13. 0x00000014: ebfffffe .... BL test ; 0x0
  14. 0x00000018: e3a00000 .... MOV r0,#0
  15. 0x0000001c: e49df004 .... LDR pc,[r13],#4
  16. ** Section #21 '.rel.text' (SHT_REL)
  17. Size : 8 bytes
  18. Symbol table '.symtab'
  19. 1 relocations applied to section #5 '.text'

 

  1. //arm处理器,arm-linux-gcc汇编结果 arm-linux-gcc -S -o hello.s hello.c
  2. .file "hello.c"
  3. .text
  4. .align 2
  5. .global test
  6. .type test, %function
  7. test:
  8. @ args = 0, pretend = 0, frame = 12
  9. @ frame_needed = 1, uses_anonymous_args = 0
  10. mov ip, sp
  11. stmfd sp!, {fp, ip, lr, pc}
  12. sub fp, ip, #4
  13. sub sp, sp, #12
  14. str r0, [fp, #-16]
  15. str r1, [fp, #-20]
  16. ldr r2, [fp, #-16]
  17. ldr r3, [fp, #-20]
  18. add r3, r2, r3
  19. str r3, [fp, #-24]
  20. ldr r3, [fp, #-24]
  21. mov r0, r3
  22. ldmea fp, {fp, sp, pc}
  23. .size test, .-test
  24. .align 2
  25. .global main
  26. .type main, %function
  27. main:
  28. @ args = 0, pretend = 0, frame = 12
  29. @ frame_needed = 1, uses_anonymous_args = 0
  30. mov ip, sp
  31. stmfd sp!, {fp, ip, lr, pc}
  32. sub fp, ip, #4
  33. sub sp, sp, #12
  34. mov r3, #10
  35. str r3, [fp, #-16]
  36. mov r3, #20
  37. str r3, [fp, #-20]
  38. ldr r0, [fp, #-16]
  39. ldr r1, [fp, #-20]
  40. bl test
  41. mov r3, r0
  42. str r3, [fp, #-24]
  43. mov r3, #0
  44. mov r0, r3
  45. ldmea fp, {fp, sp, pc}
  46. .size main, .-main
  47. .ident "GCC: (GNU) 3.3.2"

 

  1. //x86处理器,gcc汇编结果
  2. .file "hello.c"
  3. .text
  4. .globl test
  5. .type test, @function
  6. test:
  7. pushl %ebp
  8. movl %esp, %ebp
  9. subl $4, %esp
  10. movl 12(%ebp), %eax
  11. addl 8(%ebp), %eax
  12. movl %eax, -4(%ebp)
  13. movl -4(%ebp), %eax
  14. leave
  15. ret
  16. .size test, .-test
  17. .globl main
  18. .type main, @function
  19. main:
  20. pushl %ebp
  21. movl %esp, %ebp
  22. subl $24, %esp
  23. andl $-16, %esp
  24. movl $0, %eax
  25. addl $15, %eax
  26. addl $15, %eax
  27. shrl $4, %eax
  28. sall $4, %eax
  29. subl %eax, %esp
  30. movl $10, -4(%ebp)
  31. movl $20, -8(%ebp)
  32. pushl -8(%ebp)
  33. pushl -4(%ebp)
  34. call test
  35. addl $8, %esp
  36. movl %eax, -12(%ebp)
  37. movl $0, %eax
  38. leave
  39. ret
  40. .size main, .-main
  41. .section .note.GNU-stack,"",@progbits
  42. .ident "GCC: (GNU) 3.4.4 20050721 (Red Hat 3.4.4-2)"
阅读(1770) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~