C++源代码:
#include<stdio.h> int main() { int i=3; int j=2; int Array[4][3]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}}; printf("%d\n",Array[i][j]); return 0; }
Dump of assembler code for function main: 0x004012f0 <main+0>: push %ebp 0x004012f1 <main+1>: mov %esp,%ebp 0x004012f3 <main+3>: push %edi 0x004012f4 <main+4>: push %esi 0x004012f5 <main+5>: sub $0x60,%esp 0x004012f8 <main+8>: and $0xfffffff0,%esp 0x004012fb <main+11>: mov $0x0,%eax 0x00401300 <main+16>: add $0xf,%eax 0x00401303 <main+19>: add $0xf,%eax 0x00401306 <main+22>: shr $0x4,%eax 0x00401309 <main+25>: shl $0x4,%eax 0x0040130c <main+28>: mov %eax,-0x4c(%ebp) 0x0040130f <main+31>: mov -0x4c(%ebp),%eax 0x00401312 <main+34>: call 0x401878 <_alloca> 0x00401317 <main+39>: call 0x4013f8 <__main> 0x0040131c <main+44>: movl $0x3,-0xc(%ebp) 0x00401323 <main+51>: movl $0x2,-0x10(%ebp) 0x0040132a <main+58>: lea -0x48(%ebp),%edi 0x0040132d <main+61>: mov $0x402000,%esi 0x00401332 <main+66>: cld 0x00401333 <main+67>: mov $0xc,%eax 0x00401338 <main+72>: mov %eax,%ecx 0x0040133a <main+74>: rep movsl %ds:(%esi),%es:(%edi) 0x0040133c <main+76>: mov -0xc(%ebp),%edx 0x0040133f <main+79>: mov %edx,%eax 0x00401341 <main+81>: add %eax,%eax 0x00401343 <main+83>: add %edx,%eax 0x00401345 <main+85>: add -0x10(%ebp),%eax 0x00401348 <main+88>: mov -0x48(%ebp,%eax,4),%eax 0x0040134c <main+92>: mov %eax,0x4(%esp) 0x00401350 <main+96>: movl $0x403000,(%esp) 0x00401357 <main+103>: call 0x4018d8 <printf> 0x0040135c <main+108>: mov $0x0,%eax 0x00401361 <main+113>: lea -0x8(%ebp),%esp 0x00401364 <main+116>: pop %esi 0x00401365 <main+117>: pop %edi 0x00401366 <main+118>: pop %ebp 0x00401367 <main+119>: ret End of assembler dump. (gdb)看下面这一段代码:
mov -0xc(%ebp),%edx mov %edx,%eax add %eax,%eax add %edx,%eax add -0x10(%ebp),%eax把二维数组看成一个矩阵,先计算到对应的行,再计算到对应的列。