Why can assembly instructions contain multiplications in the “lea” instruction?

前端 未结 3 1269
醉酒成梦
醉酒成梦 2021-02-05 18:58

I am working on a very low level part of the application in which performance is critical.

While investigating the generated assembly, I noticed the following instructio

3条回答
  •  春和景丽
    2021-02-05 19:32

    Actually, this is not something specific to the lea instruction.

    This type of addressing is called Scaled Addressing Mode. The multiplication is achieved by a bit shift, which is trivial:

    A Left Shift

    You could do 'scaled addressing' with a mov too, for example (note that this is not the same operation, the only similarity is the fact that ebx*4 represents an address multiplication):

     mov edx, [esi+4*ebx]
    

    (source: http://www.cs.virginia.edu/~evans/cs216/guides/x86.html#memory)

    For a more complete listing, see this Intel document. Table 2-3 shows that a scaling of 2, 4, or 8 is allowed. Nothing else.

    Latency (in terms of number of cycles): I don't think this should be affected at all. A shift is a matter of connections, and selecting between three possible shifts is the matter of 1 multiplexer worth of delay.

提交回复
热议问题