News for hackers. Stuff that matters.
Re:A gentle intro to assembly with Rust by sunfish on Monday August 03, 2020 @06:32PM (#24044253)
The compiler is using push and pop here just for their side effect of adjusting the stack pointer, to keep the stack pointer 16-byte aligned.
Re:A gentle intro to assembly with Rust by saagarjha on Monday August 03, 2020 @06:37PM (#24044310)
Shouldn't the C runtime do that before calling main?
Re:A gentle intro to assembly with Rust by sunfish on Monday August 03, 2020 @07:02PM (#24044508)
It does; the stack pointer starts out aligned, but then the function does a call, and the call instruction adjusts the stack pointer by 8 bytes to push the return address, which would cause it to be misaligned. The push pushes an extra 8 bytes so that the stack pointer is aligned in the callee.
Re:A gentle intro to assembly with Rust by SilasX on Monday August 03, 2020 @08:46PM (#24045288)
Any reason not to just do some other “increment stack pointer” option?
Re:A gentle intro to assembly with Rust by glandium on Monday August 03, 2020 @09:26PM (#24045545)
The instruction is smaller. Push rax is encoded into 1 bytes, while an increment stack pointer would be 4.