I set a experiment to see whether it works or not
int *p;
p[0] = 3;
My idea is that the compiler gives a random value to p and I can consider it as a array.
But it turns out segmentation fault and I don't understand the assembly code.
0x0000000000401530 <+0>: push %rbp
0x0000000000401531 <+1>: mov %rsp,%rbp
0x0000000000401534 <+4>: sub $0x30,%rsp
0x0000000000401538 <+8>: mov %ecx,0x10(%rbp)
0x000000000040153b <+11>: mov %rdx,0x18(%rbp)
0x000000000040153f <+15>: callq 0x402170 <__main>
0x0000000000401544 <+20>: mov -0x8(%rbp),%rax
=> 0x0000000000401548 <+24>: movl $0x3,(%rax)
0x000000000040154e <+30>: mov $0x0,%eax
0x0000000000401553 <+35>: add $0x30,%rsp
0x0000000000401557 <+39>: pop %rbp
0x0000000000401558 <+40>: retq
I searched on google, mov is Intel style and movl is AT&T style. How come these two style come together?
At this line:
mov -0x8(%rbp),%rax
It seems like move the value of address rbp-0x8 to register rax, right? Is this "-0x8(%rbp)" a random value goes to p?
I think %rax is not p, because at next line CPU give $0x3 to %rax. It seems the %rax is the first memory of the array.
How do I interpret this assembly code? Thank you.