使用的开发工具为
最新版本:(29.04.2011更新) Binutils-2.21
Newlib-1.19.0
GCC-4.6.0
GDB-7.2 下面贴一下自己的代码,以备查阅。(代码不能实际运行,只是为了看生成的反汇编代码)
test.s
- .text
-
.global _start
-
.code 16
-
.syntax unified
-
_start:
-
.word 0x20002000
-
.word reset
-
.type reset, function
-
reset:
-
ldr r0,=main
-
bx r0
-
.end
main.c
- int main(void)
-
{
-
float a=3.1415926,b=12.9873421,result;
-
result=a*b*b;
-
while(1);
-
return 0;
-
}
Makefile
- test.elf : test.s main.c
- arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mfloat-abi=hard -mthumb -o test.o test.s
- arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -o main.o main.c
- arm-none-eabi-ld -Ttext 0x0 test.o main.o -o test.elf
- arm-none-eabi-objcopy -O binary -S test.elf test.bin
- arm-none-eabi-objdump -D -m arm test.elf >_test.dis
- dos2unix _test.dis
-
clean:
- rm test.o main.o test.elf _test.dis test.bin
只有这3个文件,可以看到在Makefile中有"-mfloat-abi=hard",这个可以用来生成FPU代码(cortex-m4带DSP运算单元)。
生成的反汇编代码如下:
- test.elf: file format elf32-littlearm
-
-
-
Disassembly of section .text:
-
-
00000000 <_start>:
-
0: 20002000 andcs r2, r0, r0
-
4: 00000009 andeq r0, r0, r9
-
-
00000008 :
-
8: 4800 ldr r0, [pc, #0] ; (c )
-
a: 4700 bx r0
-
c: 00000011 andeq r0, r0, r1, lsl r0
-
-
00000010 :
-
10: b480 push {r7}
-
12: b085 sub sp, #20
-
14: af00 add r7, sp, #0
-
16: 4b08 ldr r3, [pc, #32] ; (38 )
-
18: 60fb str r3, [r7, #12]
-
1a: 4b08 ldr r3, [pc, #32] ; (3c )
-
1c: 60bb str r3, [r7, #8]
-
1e: ed97 7a03 vldr s14, [r7, #12]
-
22: edd7 7a02 vldr s15, [r7, #8]
-
26: ee67 7a27 vmul.f32 s15, s14, s15
-
2a: ed97 7a02 vldr s14, [r7, #8]
-
2e: ee67 7a87 vmul.f32 s15, s15, s14
-
32: edc7 7a01 vstr s15, [r7, #4]
-
36: e7fe b.n 36
-
38: 40490fda ldrdmi r0, [r9], #-250 ; 0xffffff06
-
3c: 414fcc27 cmpmi pc, r7, lsr #24
----------------------------------------------------------------------------------------------------------------------------------
生成软件浮点代码:
Makefile:
- test.elf : test.s main.c
- arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mfloat-abi=soft -mthumb -o test.o test.s
- arm-none-eabi-gcc -c -gdwarf-2 -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -o main.o main.c
- arm-none-eabi-gcc -Ttext 0x0 -mcpu=cortex-m4 -mfloat-abi=soft -mthumb -nostartfiles test.o main.o -o test.elf
- arm-none-eabi-objcopy -O binary -S test.elf test.bin
- arm-none-eabi-objdump -D -m arm test.elf >_test.dis
- dos2unix _test.dis
-
clean:
- rm test.o main.o test.elf _test.dis test.bin
生成结果如下:
- 00000000 <_start>:
-
0: 20002000 andcs r2, r0, r0
-
4: 00000009 andeq r0, r0, r9
-
-
00000008 :
-
8: 4800 ldr r0, [pc, #0] ; (c )
-
a: 4700 bx r0
-
c: 00000011 andeq r0, r0, r1, lsl r0
-
-
00000010 :
-
10: b580 push {r7, lr}
-
12: b084 sub sp, #16
-
14: af00 add r7, sp, #0
-
16: 4b08 ldr r3, [pc, #32] ; (38 )
-
18: 60fb str r3, [r7, #12]
-
1a: 4b08 ldr r3, [pc, #32] ; (3c )
-
1c: 60bb str r3, [r7, #8]
-
1e: 68f8 ldr r0, [r7, #12]
-
20: 68b9 ldr r1, [r7, #8]
-
22: f000 f80d bl 40 <__aeabi_fmul>
-
26: 4603 mov r3, r0
-
28: 4618 mov r0, r3
-
2a: 68b9 ldr r1, [r7, #8]
-
2c: f000 f808 bl 40 <__aeabi_fmul>
-
30: 4603 mov r3, r0
-
32: 607b str r3, [r7, #4]
-
34: e7fe b.n 34
-
36: bf00 nop
-
38: 40490fda ldrdmi r0, [r9], #-250 ; 0xffffff06
-
3c: 414fcc27 cmpmi pc, r7, lsr #24
-
-
00000040 <__aeabi_fmul>:
-
40: f04f 0cff mov.w ip, #255 ; 0xff
-
44: ea1c 52d0 ands.w r2, ip, r0, lsr #23
-
48: bf1e ittt ne
-
4a: ea1c 53d1 andsne.w r3, ip, r1, lsr #23
-
4e: ea92 0f0c teqne r2, ip
-
52: ea93 0f0c teqne r3, ip
-
56: d06f beq.n 138 <__aeabi_fmul+0xf8>
-
58: 441a add r2, r3
-
5a: ea80 0c01 eor.w ip, r0, r1
-
5e: 0240 lsls r0, r0, #9
-
60: bf18 it ne
- ........(以下省略)
阅读(2589) | 评论(0) | 转发(0) |