Looking at the output of a compiler is a great way to quickly learn the basics of assembly coding for a particular platform, but learning the principles of programming in assembler and machine architecture is an entirely different story. Knuth's 1st volume remains the best in that regard.
> And indeed, inside main we can see push rax - saving the value in the register rax to the stack, then a call to our add function, then we pop rax off the stack. The push call pop sequence is to preserve whatever values are in the registers used in add.
There's really no need to save rax here; I know that optimizations are off but I'm still curious why rustc thinks this is necessary…
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.
You are correct, Sir, but application-level people are happy to write a few lines of funny looking mnemonics to optimize their boring sort functions and then brag on LinkedIn. Also, if you are still in "_hk", please stop wasting time and get your friends and family out.