Assembly instructions: lea

lea instruction variant (by size):

leaw # 2 bytes 
leal # 4 bytes 
leaq # 8 bytes

lea Usage:

leaq a(b, c, d), %rax

First lea instruction is mov instruction variant, it is said, lea instruction is x86 architecture, is one of the oldest but in some ways is the most amazing in terms of instruction.

On the surface, it is very simple to do, is calculated according to the source operand in parentheses address, then the address is loaded into the destination register.

For example: leaq a (b, c, d),% rax to calculate the address of a + b + c * d, and then loaded into the final address in register rax.

Leaq most funny is not referenced in the source operand register, simply calculated. That this is entirely possible to use it as a multiply instruction.

E.g:

  rbx * 2 

movq $8, %rbx
leaq (, %rbx, 2), %rax

  rbx * 3

movq $8, %rbx
leaq (%rbx, %rbx, 2), %rax

  rbx * 3 - 1

movq $8, %rbx
leaq -1(%rbx, %rbx, 2), %rax

 

When using lea instruction:

    Five or six instructions before attempting to complete a multiplication, see if you can replace it by twenty-three lea instruction.

Precautions:

    d is in the range of 1,2,4,8 (64 cpu)

Original connection: https://my.oschina.net/guonaihong/blog/508907

Guess you like

Origin www.cnblogs.com/YangARTuan/p/11628591.html