I am looking at x86-64 ISA, and the leaq
instruction is used to load the address to a designated register and I am looking at the following example:
long m12(long x){
return x *12;
}
which is equivalent to
leaq (%rdi, %rdi, 2), %rax
salq $2, %rax
I vaguely get what it means here is that leaq
does not reference the memory location given by the computed "address", instead it relocates the computed "address" directly. However, %rdi
just holds an integer. How is that an address in any sense?
LEA
doesn't actually have anything to do with addresses. While it's designed for use with addresses and offsets, the numbers don't actually have to be addresses and offsets. So it's often used to efficiently perform such sums on non-addresses but addresses as well.
leaq (%rdi, %rdi, 2), %rax // rax = rdi + rdi*2 = 3*rdi
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.