简体   繁体   English

汇编中的有效地址

[英]effective address in assembly

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:我正在查看 x86-64 ISA,并且leaq指令用于将地址加载到指定的寄存器,我正在查看以下示例:

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.我隐约明白这里的意思是leaq不引用计算出的“地址”给定的内存位置,而是直接重新定位计算出的“地址”。 However, %rdi just holds an integer.但是, %rdi只保存一个整数。 How is that an address in any sense?从某种意义上说,这是一个地址吗?

LEA doesn't actually have anything to do with addresses. LEA实际上与地址没有任何关系。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM