I compile following code
int foo(int num) {
int &numReference = num;
int numVarible = num;
return numVarible;
}
output assemble translation.
foo(int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-20], edi
lea rax, [rbp-20]
mov QWORD PTR [rbp-8], rax
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-12], eax
mov eax, DWORD PTR [rbp-12]
pop rbp
ret
int &numReference = num; output assemble:
lea rax, [rbp-20]
mov QWORD PTR [rbp-8], rax
int numVarible = num; output assemble:
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-12], eax
the question 1 is what's the difference about memeory comsumption.
When I change code from "return numVarible;" to "return numReference ;". assemble changes from
mov eax, DWORD PTR [rbp-12]
to
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax]
the question 2 is: when using reference, why assemble shows more line?