pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
I have big question regarding explanation of "$32" in third instruction. The information from search and blogs specifies that in above third instruction we are reserving certain "bytes" of space for stack. From doc, %rsp is 64 bit register and %esp is 32 bit.
Is "$32" means 32 bytes ?($number means constant ?) If yes then how are we allocating 32 bytes on 64 bit register? Above instruction were generated from "otool". I am using macbook pro.
I am just trying to learn a small things about assembly.
Thanks.
Is "$32" means 32 bytes ?($number means constant ?) If yes then how are we allocating 32 bytes on 64 bit register?
These 32 bytes are not allocated on 64 bit register. They are allocated on the stack. By lowering the stackpointer (which is in %rsp) the address range from %rsp to %rsp+31 is at our disposal for storing data.
In 64-bit code, 128 bytes are reserved for you already, so you don't have to mess with the stack pointer in leaf functions, which consequently means you probably don't have to push/pop %rbp. Just use %rsp-128 to %rsp-1 for your data.
This reserved area is called the red-zone:
http://eli.thegreenplace.net/2011/09/06/stack-frame-layout-on-x86-64/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With