- 论坛徽章:
- 0
|
原帖由 antigloss 于 2007-5-13 09:28 发表
那编译器可能将指针 p 和 p1 放到寄存器上,但 "abcd" 不会在寄存器上。
- $ objdump -S register.o
- register.o: file format elf32-i386
- Disassembly of section .text:
- 00000000 <main>:
- #include <stdio.h>
- int
- main()
- {
- 0: 55 push %ebp
- 1: 89 e5 mov %esp,%ebp
- 3: 83 ec 18 sub $0x18,%esp
- 6: 83 e4 f0 and $0xfffffff0,%esp
- 9: b8 00 00 00 00 mov $0x0,%eax
- e: 29 c4 sub %eax,%esp
- 10: a1 00 00 00 00 mov 0x0,%eax
- 15: 89 45 e8 mov %eax,0xffffffe8(%ebp)
- register char a[4] = {0, 1, 2, 3};
- 18: b8 00 00 00 00 mov $0x0,%eax
- 1d: ba 01 00 00 00 mov $0x1,%edx
- 22: 88 d4 mov %dl,%ah
- 24: 25 ff ff 00 ff and $0xff00ffff,%eax
- 29: 0d 00 00 02 00 or $0x20000,%eax
- 2e: 25 ff ff ff 00 and $0xffffff,%eax
- 33: 0d 00 00 00 03 or $0x3000000,%eax
- a[0]=0;
- 38: b0 00 mov $0x0,%al
- a[1]=1;
- 3a: ba 01 00 00 00 mov $0x1,%edx
- 3f: 88 d4 mov %dl,%ah
- a[2]=2;
- 41: 25 ff ff 00 ff and $0xff00ffff,%eax
- 46: 0d 00 00 02 00 or $0x20000,%eax
- a[3]=3;
- 4b: 25 ff ff ff 00 and $0xffffff,%eax
- 50: 0d 00 00 00 03 or $0x3000000,%eax
- printf("%d\n%d\n%d\n%d\n", a[0], a[1], a[2], a[3]);
- 55: 83 ec 0c sub $0xc,%esp
- 58: 89 c2 mov %eax,%edx
- 5a: c1 fa 18 sar $0x18,%edx
- 5d: 0f be d2 movsbl %dl,%edx
- 60: 52 push %edx
- 61: 89 c2 mov %eax,%edx
- 63: c1 e2 08 shl $0x8,%edx
- 66: c1 fa 18 sar $0x18,%edx
- 69: 0f be d2 movsbl %dl,%edx
- 6c: 52 push %edx
- 6d: 0f be d4 movsbl %ah,%edx
- 70: 0f be d2 movsbl %dl,%edx
- 73: 52 push %edx
- 74: 0f be c0 movsbl %al,%eax
- 77: 50 push %eax
- 78: 68 00 00 00 00 push $0x0
- 7d: e8 fc ff ff ff call 7e <main+0x7e>
- 82: 83 c4 20 add $0x20,%esp
- return 0;
- 85: b8 00 00 00 00 mov $0x0,%eax
- }
- 8a: 8b 55 e8 mov 0xffffffe8(%ebp),%edx
- 8d: 3b 15 00 00 00 00 cmp 0x0,%edx
- 93: 74 13 je a8 <main+0xa8>
- 95: 83 ec 08 sub $0x8,%esp
- 98: ff 75 e8 pushl 0xffffffe8(%ebp)
- 9b: 68 0d 00 00 00 push $0xd
- a0: e8 fc ff ff ff call a1 <main+0xa1>
- a5: 83 c4 10 add $0x10,%esp
- a8: c9 leave
- a9: c3 ret
- $
复制代码
其实我不该拿汇编代码出来 
. |
|