Skip to content
Advertisement

Strange pointer position in the stack

I wrote this simple code:

JavaScript

and I’ve disassembled it to see what the compiler does. Using objdump I obtain:

JavaScript

I can understand everything except for the mov QWORD PTR [rbp-0x10],0x0, this correspond (I think)to p=NULL; but from mov QWORD PTR [rbp-0x8],rax I know that my pointer is on rbp-0x8 and it seems correct (the size of a pointer is 8bytes).

So why mov QWORD PTR [rbp-0x10],0x0 is called on rbp-0x10?

Also I don’t know why xor eax,eax is called; for allignment?(if so why don’t use nop). P.S I know that is sets eax to zero, but why ?

Advertisement

Answer

From these lines

JavaScript

It is clear that these assembler instructions correspond to

JavaScript

So the local variable p is placed at [rbp-0x10] and occupies a QWORD starting at [rbp-0x10] through [rbp-0x8] ( rbp-0x10 + 0x8 == rbp-0x8)

Advertisement