3 ms·
The source of the confusion is because a lot of assemblers will let you write [EBP+reg] or even just [EBP] (and disassemblers may correspondingly show those for
by userbinator 7y ago
The source of the confusion is because a lot of assemblers will let you write [EBP+reg] or even just [EBP] (and disassemblers may correspondingly show those forms) but that's not how it's actually encoded; since the days of the 8086 (and BP, 16 bits) it was intended that BP would always be used with an offset to access memory in a stack frame (hence it uses the SS: segment by default), and thus the position in the encoding for BP without an offset was instead used for absolute addressing. This tradition continued in the 32-bit and now 64-bit (where R13 is the "high REX" of RBP), thus if you write [EBP+ECX], it actually gets encoded as [EBP+ECX+0].
There's the third operand --- it's just "hidden". Hence the somewhat misleading wording of that advice.
- acqq 7y ago> thus if you write [EBP+ECX], it actually gets encoded as [EBP+ECX+0]. And that's not as important as you make it appear. If you write [EBP + 24] (where the index register is simply not used), do you think that's a "slow" LEA? The [EBP + 24] form is what my (and I guess most of other's) compiler produced most of the time. Open any program with disassembler and try to count how often index register is ever used with EBP, and how often no index register is used. Former happens practically never, the later (no index) is very common.