9

私はこれを正しく読んでいることを確認したいだけです:

movl 12(%ebp), %edx
leal (%edx, %edx, 4), %eax

最初の行を次のように読み取ります: edx = [epb + 12]、2 行目を次のように読み取ります。eax = edx + edx*4

誰でも明確にできますか?

また、次の 2 行がある場合はどうなるでしょうか。

leal (%edx, %edx, 4), %eax
leal (%edx, %edx, 2), %eax

2 行目が実行されると、eaxレジスタは上書きされますか?

そして、eax = edx + edx*4アドレスに4を掛けていますか?それとも4によるアドレスの内容?

4

2 に答える 2

9

The instruction movl 12(%ebp), %edx means: edx = [ebp + 12]. This is a memory reference (a read operation) to the address ebp + 12 whose contents (a double word) are read to edx register.

The instruction leal (%edx, %edx, 4), %eax means: eax = edx * 5 (which is a simplification of eax = edx + edx * 4). The leal instruction doesn't do memory references. It only performs arithmetic with registers.

As an answer to your second question: Yes, eax would be overwritten because the instruction leal (%edx, %edx, 2), %eax means eax = edx * 3 which is different from the first instruction, eax = edx * 5.

于 2012-02-05T21:45:38.520 に答える
8

あなたが正しい。このLEA命令は、実効アドレスをロードするために使用され、アドレス演算に使用できます。フラグが必要ない場合は、通常の演算にも使用できます。

于 2012-02-05T21:45:23.267 に答える