You mixed up prologue (start) with Epilogue(end). Prologue is the start of function call and Epilogue is the end. It took me lots of time to differnciate them. An easy way to remember the order is to link letter E from Epilogue with End ( both words start with letter E). In addition, the size of all registers is 8 bytes in 64bit arch.
Nice video! I found it pretty clear. One note: I think the reason why there is no sub done on rsp when d0 is a tail call is that the compiler is using the red zone in this case.
He explained it a bit weird. The reason d0 is first reserving space on the stack and then moving all arguments(a1, a2, a3) passed to it by registers to the stack, is that printf could use the registers(edi, esi, edx) to be other values and would therefore overwrite the parameters passed to d0. d0 needs to reserve space because it stores local variables (a1, a2, a3, a, b) on the stack. main doesn't have local variables and therefore doesn't need to reserve any space. Also the reason the substrate instruction disappeared when he removed printf is because "reservating space" means moving the value telling the next (inner) function epilog (printf) where it can start to put it's local variables so they are located after the variables of the enclosing function instead of at the same location. When he removes printf d0 has no function to tell that and it would basically sub 20 and add 20 without anything looking at that value change making it a noop.
You mixed up prologue (start) with Epilogue(end). Prologue is the start of function call and Epilogue is the end. It took me lots of time to differnciate them. An easy way to remember the order is to link letter E from Epilogue with End ( both words start with letter E). In addition, the size of all registers is 8 bytes in 64bit arch.
Nice video! I found it pretty clear. One note: I think the reason why there is no sub done on rsp when d0 is a tail call is that the compiler is using the red zone in this case.
do you have a video on analyzing partial contents of stack memory?
why doesn't the main's Stack Frame also subtract the stack pointer to reserve memory for the calling function 'd' ?
He explained it a bit weird. The reason d0 is first reserving space on the stack and then moving all arguments(a1, a2, a3) passed to it by registers to the stack, is that printf could use the registers(edi, esi, edx) to be other values and would therefore overwrite the parameters passed to d0. d0 needs to reserve space because it stores local variables (a1, a2, a3, a, b) on the stack.
main doesn't have local variables and therefore doesn't need to reserve any space.
Also the reason the substrate instruction disappeared when he removed printf is because "reservating space" means moving the value telling the next (inner) function epilog (printf) where it can start to put it's local variables so they are located after the variables of the enclosing function instead of at the same location. When he removes printf d0 has no function to tell that and it would basically sub 20 and add 20 without anything looking at that value change making it a noop.
I dont know why, but I really liked that frame 0:32
very well explained
great, thank you!
Glad it was helpful FunkyKong!
why not "sub rsp, 0x1c" , but "sub rsp, 0x20"? why 4 bytes is extra?
I suspect the reason is to ensure 64-bit (8-byte) alignment.
0x1c is not a multiple of 8.
To look at assembler, there is the S switch in gcc "gcc -S -o prog.s prog.c".
I'm pretty sure the EAX 0x0 is the return value of printf
You are correct my dude :)
Good video!
Thank you
I think you mixed up epilogue and prologue...
My mistake. Thank you for keeping me honest. Hope you enjoyed the video.
This doesn't seem like Windows..
Buy a better mic man
Lol, I did
dont buy a better mic sir we are not here for asmr
shit