- 论坛徽章:
- 0
|
本帖最后由 rocky1972 于 2010-02-05 16:55 编辑
[root@localhost example]# ls
main.c Makefile
[root@localhost example]# cat main.c
#include <stdio.h>
#include <stdlib.h>
int foo(int a, int b)
{
return (a + b);
}
int dumm(int a, int b ,int c , int d,int e)
{
return (a + b + c +d);
}
int main(int argc ,char ** argv)
{
int c;
c = foo(1,2);
c = dumm(1,2,3,4,5);
return c;
}
[root@localhost example]# cat Makefile
all: build_arm build_mips show
TARGET_NAME = helloworld
SOUCRE_FILE = main.c
build_arm:
arm-linux-gcc $(SOUCRE_FILE) -o $(TARGET_NAME).arm.elf
arm-linux-objdump -D $(TARGET_NAME).arm.elf > $(TARGET_NAME).arm.objdump
arm-linux-objcopy -O binary -R .note -R .note.gnu.build-id -R .comment -S $(TARGET_NAME).arm.elf $(TARGET_NAME).arm.bin
build_mips:
mips-linux-gcc $(SOUCRE_FILE) -o $(TARGET_NAME).mips.elf
mips-linux-objdump -D $(TARGET_NAME).mips.elf > $(TARGET_NAME).mips.objdump
mips-linux-objcopy -O binary -R .note -R .note.gnu.build-id -R .comment -S $(TARGET_NAME).mips.elf $(TARGET_NAME).mips.bin
show:
ls -al *bin
ls -al *objdump
ls -al *elf
clean:
rm -rf *.elf *.bin *.objdump
[root@localhost example]# make
arm-linux-gcc main.c -o helloworld.arm.elf
arm-linux-objdump -D helloworld.arm.elf > helloworld.arm.objdump
arm-linux-objcopy -O binary -R .note -R .note.gnu.build-id -R .comment -S helloworld.arm.elf helloworld.arm.bin
mips-linux-gcc main.c -o helloworld.mips.elf
mips-linux-objdump -D helloworld.mips.elf > helloworld.mips.objdump
mips-linux-objcopy -O binary -R .note -R .note.gnu.build-id -R .comment -S helloworld.mips.elf helloworld.mips.bin
ls -al *bin
-rwxr-xr-x 1 root root 34160 02-05 16:43 helloworld.arm.bin
-rwxr-xr-x 1 root root 67696 02-05 16:43 helloworld.mips.bin
ls -al *objdump
-rw-r--r-- 1 root root 25486 02-05 16:43 helloworld.arm.objdump
-rw-r--r-- 1 root root 19243 02-05 16:43 helloworld.mips.objdump
ls -al *elf
-rwxr-xr-x 1 root root 7516 02-05 16:43 helloworld.arm.elf
-rwxr-xr-x 1 root root 5878 02-05 16:43 helloworld.mips.elf
[root@localhost example]#
比较两个binary的大小发现ARM的代码密度要比MIPS高一倍。
对单个函数 foo函数进行反汇编:
================================= ARM ==================================
000083a0 <foo>:
83a0: e1a0c00d mov ip, sp
83a4: e92dd800 stmdb sp!, {fp, ip, lr, pc}
83a8: e24cb004 sub fp, ip, #4 ; 0x4
83ac: e24dd008 sub sp, sp, #8 ; 0x8
83b0: e50b0010 str r0, [fp, #-16]
83b4: e50b1014 str r1, [fp, #-20]
83b8: e51b2010 ldr r2, [fp, #-16]
83bc: e51b3014 ldr r3, [fp, #-20]
83c0: e0823003 add r3, r2, r3
83c4: e1a00003 mov r0, r3
83c8: e24bd00c sub sp, fp, #12 ; 0xc
83cc: e89da800 ldmia sp, {fp, sp, pc}
ARM 用 12 条指令完成
================================= MIPS ==================================
00400750 <foo>:
400750: 27bdfff8 addiu sp,sp,-8
400754: afbe0004 sw s8,4(sp)
400758: 03a0f021 move s8,sp
40075c: afc40008 sw a0,8(s
400760: afc5000c sw a1,12(s
400764: 8fc30008 lw v1,8(s
400768: 8fc2000c lw v0,12(s
40076c: 00000000 nop
400770: 00621021 addu v0,v1,v0
400774: 03c0e821 move sp,s8
400778: 8fbe0004 lw s8,4(sp)
40077c: 27bd0008 addiu sp,sp,8
400780: 03e00008 jr ra
400784: 00000000 nop
MIPS 用14条指令, 多出来的两条指令为nop来充当delay slot
但是MIPS 的FAE 培训的时候讲到 , MIPS寄存器数量比ARM 要多, 所以代码密度和执行效率较ARM 要高一些。。。。。。。 |
|