How does lea instruction get the operand's address?

This question already has an answer here:

  • What's the purpose of the LEA instruction? 14 answers

  • The LEA instruction uses the effective address (EA) part of the CPU to do certain kinds of arithmetic without using the ALU. The EA module can do very specific kinds of arithmetic that is used for address calculation, but can also be used for other things if what you need is one of the things it specifically provides.

    By not using the ALU for this EA calculation, the ALU can be busy doing something else at the same time and you can avoid a pipeline stall.


    The idea that lea doesn't go through the ALU is outdated and has been wrong for over a decade. It goes through one of the ALUs - of which there will be several, and that is extremely unlikely to be a bottleneck. It actually takes time. It's not faster than an add .

    But that doesn't mean it isn't useful. Unlike add , it can have a destination that differs from both inputs, so it can save a mov , and it can take an extra constant so you can do two add s and a mov all in one. The scaling is also nice, and all combined you can do something like a = b * 9 + 5 all in one lea a, [b + b * 8 + 5] . Such "complex" forms of lea are often slower than than simpler 2-operand forms of lea .

    链接地址: http://www.djcxy.com/p/72370.html

    上一篇: 在x86程序集中的LEA

    下一篇: lea指令如何获得操作数的地址?