LEAL: leal S, D ? ?-> ? ?D ← &S
在 CSAPP (Computer Systems: A Programmer’s Perspective) 中,對 LEAL 指令用作簡單算術運算的情況,給出了一個例子:
For example, if register %edx contains value x, leal 7(%edx,%edx,4), %eax will set register %eax to 5x + 7.
正確理解邏輯為:
1. 設%edx的值為x
2. 7(%edx,%edx,4) 為變質尋址,目標內存地址為5x+7
3. 設儲存在地址5x+7的值為y。然而LEAL并不尋址,它只取y的地址。y的地址即為5x+7。因此,LEAL的左操作數為5x+7
CSAPP描述為:
It has the form of an instruction that reads from memory to a register, but it does not reference memory at all. Its first operand appears to be a memory reference, but instead of reading from the designated location, the instruction copies the effective address to the destination.
4. LEAL將y的地址,5x+7,賦給%eax
至此,LEAL實現了簡單算術功能。