Chinaunix首页 | 论坛 | 博客
  • 博客访问: 240332
  • 博文数量: 27
  • 博客积分: 358
  • 博客等级: 一等列兵
  • 技术积分: 291
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 17:35
文章分类

全部博文(27)

文章存档

2015年(1)

2014年(4)

2013年(6)

2012年(4)

2011年(12)

分类: 嵌入式

2011-05-06 22:42:12

使用的开发工具为最新版本:(29.04.2011更新)
Binutils-2.21
Newlib-1.19.0
GCC-4.6.0
GDB-7.2 
下面贴一下自己的代码,以备查阅。(代码不能实际运行,只是为了看生成的反汇编代码)

test.s
  1. .text
  2. .global _start
  3. .code 16
  4. .syntax unified
  5. _start:
  6. .word 0x20002000
  7. .word reset
  8. .type reset, function
  9. reset:
  10. ldr r0,=main
  11. bx r0
  12. .end

main.c
  1. int main(void)
  2. {
  3.         float a=3.1415926,b=12.9873421,result;
  4.         result=a*b*b;
  5.         while(1);
  6.         return 0;
  7. }

Makefile
  1. test.elf : test.s main.c
  2. arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mfloat-abi=hard -mthumb -o test.o test.s
  3. arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -o main.o main.c
  4. arm-none-eabi-ld -Ttext 0x0 test.o main.o -o test.elf
  5. arm-none-eabi-objcopy -O binary -S test.elf test.bin
  6. arm-none-eabi-objdump -D -m arm test.elf >_test.dis
  7. dos2unix _test.dis
  8. clean:
  9. rm test.o main.o test.elf _test.dis test.bin

只有这3个文件,可以看到在Makefile中有"-mfloat-abi=hard",这个可以用来生成FPU代码(cortex-m4带DSP运算单元)。

生成的反汇编代码如下:
  1. test.elf: file format elf32-littlearm
  2. Disassembly of section .text:
  3. 00000000 <_start>:
  4. 0: 20002000 andcs r2, r0, r0
  5. 4: 00000009 andeq r0, r0, r9
  6. 00000008 :
  7. 8: 4800 ldr r0, [pc, #0] ; (c )
  8. a: 4700 bx r0
  9. c: 00000011 andeq r0, r0, r1, lsl r0
  10. 00000010
    :
  11. 10: b480 push {r7}
  12. 12: b085 sub sp, #20
  13. 14: af00 add r7, sp, #0
  14. 16: 4b08 ldr r3, [pc, #32] ; (38 )
  15. 18: 60fb str r3, [r7, #12]
  16. 1a: 4b08 ldr r3, [pc, #32] ; (3c )
  17. 1c: 60bb str r3, [r7, #8]
  18. 1e: ed97 7a03 vldr s14, [r7, #12]
  19. 22: edd7 7a02 vldr s15, [r7, #8]
  20. 26: ee67 7a27 vmul.f32 s15, s14, s15
  21. 2a: ed97 7a02 vldr s14, [r7, #8]
  22. 2e: ee67 7a87 vmul.f32 s15, s15, s14
  23. 32: edc7 7a01 vstr s15, [r7, #4]
  24. 36: e7fe b.n 36
  25. 38: 40490fda ldrdmi r0, [r9], #-250 ; 0xffffff06
  26. 3c: 414fcc27 cmpmi pc, r7, lsr #24
----------------------------------------------------------------------------------------------------------------------------------
生成软件浮点代码:
Makefile:
  1. test.elf : test.s main.c
  2. arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mfloat-abi=soft -mthumb -o test.o test.s
  3. arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -o main.o main.c
  4. arm-none-eabi-gcc -Ttext 0x0 -mcpu=cortex-m4 -mfloat-abi=soft -mthumb -nostartfiles test.o main.o -o test.elf
  5. arm-none-eabi-objcopy -O binary -S test.elf test.bin
  6. arm-none-eabi-objdump -D -m arm test.elf >_test.dis
  7. dos2unix _test.dis
  8. clean:
  9. rm test.o main.o test.elf _test.dis test.bin
生成结果如下:
  1. 00000000 <_start>:
  2. 0: 20002000 andcs r2, r0, r0
  3. 4: 00000009 andeq r0, r0, r9
  4. 00000008 :
  5. 8: 4800 ldr r0, [pc, #0] ; (c )
  6. a: 4700 bx r0
  7. c: 00000011 andeq r0, r0, r1, lsl r0
  8. 00000010
    :
  9. 10: b580 push {r7, lr}
  10. 12: b084 sub sp, #16
  11. 14: af00 add r7, sp, #0
  12. 16: 4b08 ldr r3, [pc, #32] ; (38 )
  13. 18: 60fb str r3, [r7, #12]
  14. 1a: 4b08 ldr r3, [pc, #32] ; (3c )
  15. 1c: 60bb str r3, [r7, #8]
  16. 1e: 68f8 ldr r0, [r7, #12]
  17. 20: 68b9 ldr r1, [r7, #8]
  18. 22: f000 f80d bl 40 <__aeabi_fmul>
  19. 26: 4603 mov r3, r0
  20. 28: 4618 mov r0, r3
  21. 2a: 68b9 ldr r1, [r7, #8]
  22. 2c: f000 f808 bl 40 <__aeabi_fmul>
  23. 30: 4603 mov r3, r0
  24. 32: 607b str r3, [r7, #4]
  25. 34: e7fe b.n 34
  26. 36: bf00 nop
  27. 38: 40490fda ldrdmi r0, [r9], #-250 ; 0xffffff06
  28. 3c: 414fcc27 cmpmi pc, r7, lsr #24
  29. 00000040 <__aeabi_fmul>:
  30. 40: f04f 0cff mov.w ip, #255 ; 0xff
  31. 44: ea1c 52d0 ands.w r2, ip, r0, lsr #23
  32. 48: bf1e ittt ne
  33. 4a: ea1c 53d1 andsne.w r3, ip, r1, lsr #23
  34. 4e: ea92 0f0c teqne r2, ip
  35. 52: ea93 0f0c teqne r3, ip
  36. 56: d06f beq.n 138 <__aeabi_fmul+0xf8>
  37. 58: 441a add r2, r3
  38. 5a: ea80 0c01 eor.w ip, r0, r1
  39. 5e: 0240 lsls r0, r0, #9
  40. 60: bf18 it ne
  41. ........(以下省略)

阅读(3896) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~