正確理解 LEAL (Load Effective Address) 指令

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實現了簡單算術功能。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 原文: GCC-Inline-Assembly-HOWTO 1. 簡介(Introduction.) 1.1 Co...
    桂糊涂閱讀 4,562評論 1 5
  • 我的思念像細雨后的春草一樣拔節生長 我的牽掛像檐前的雨簾一樣如絲如網 纖細悵惘的心弦 不成調的琴聲中 依然縈繞你模...
    萬道我為法閱讀 306評論 0 0
  • 處暑悄然至,天長杳無跡。 蒸蒸熱氣散,悠悠涼風起! 午間搖素扇,凌晨添薄衣。 莫愁華葉衰,流年秋聲里!
    逸塵居士閱讀 246評論 0 0