I've used the following two different approaches to referencing a variable in assembly. Using the variable itself:
# Move a variable, directly referencing it rather than relative to %rip
movzbq my_var, %r14
leaq my_var, %r15
And then using the relative address to rip
:
# Move a variable, then its address into two registers
movzbq my_var(%rip), %r14
leaq my_var(%rip), %r15
I find the first one (of course) more readable than the second. What are the differences between the two different approaches, and is one preferred over another?