Does something like [ebp*2+edx+50] gets calculated the same for the LEA instruction and for MOV or the rest of 32-bit instructions? From what the manuals say, it seems like that.
Also, how is that address calculated actually?
Does something like:
[ebp*2+edx+50]
Assuming that:
Default segment == always DS, except when the "base" register is EBP or ESP (in this case would be EDX)?
EBP = 3
EDX = 4
Would that be calculated like this?:
(3*2+4+50) == DS:60 -- (with cyclic 32-bit numbers if they overflow when added)
I have been trying to inspect the Bochs memory and seems that when EBP or ESP are the "base register" (e.g. if it instead was something like [ebp+edx*2+50] or [esp+edx*2+50]), the SS segment is used, LEA seems to work as described, and I'm fairly sure about everything else I have pointed out.
Is it correct?
Question for addressings like [ebp*2+edx+50]
Question for addressings like [ebp*2+edx+50]
YouTube:
http://youtube.com/@AltComp126
My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
http://youtube.com/@AltComp126
My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
Re: Question for addressings like [ebp*2+edx+50]
Yes, you basically have it right. That is the point of the LEA opcode, is to give you access to the values calculated by those addressing modes. The one thing you may not have right is that LEA stops before doing anything with segments. It just calculates the values inside the brackets.
If you are using any other opcode than LEA, then you are correct about the DS: and SS: segment usage.
LEA is nice for calculating some "multiples" in place. That is: LEA EBX, [EBX+ 2*EBX]
is an easy and really fast way to multiply by 3. 3, 5, and 9 become very interesting multipliers.
No EFLAGS bits are ever set with LEA, and in general you need to be careful about overflows when using that sort of 32bit/extended addressing.
But this is also nice if you are trying not to mess up your current EFLAGS settings.
If you are using any other opcode than LEA, then you are correct about the DS: and SS: segment usage.
LEA is nice for calculating some "multiples" in place. That is: LEA EBX, [EBX+ 2*EBX]
is an easy and really fast way to multiply by 3. 3, 5, and 9 become very interesting multipliers.
No EFLAGS bits are ever set with LEA, and in general you need to be careful about overflows when using that sort of 32bit/extended addressing.
But this is also nice if you are trying not to mess up your current EFLAGS settings.
Re: Question for addressings like [ebp*2+edx+50]
The general form is [BASE + INDEX * SCALE + DISPLACEMENT]. In your example the base is EDX because EBP is scaled. If the scale is omitted, [ebp + edx + 1234] and [edx + ebp + 1234] look the same, but the assembler will probably assume that the base is EBP in the first case (SS-relative) and EDX in the latter (DS-relative) because the first register is usually the base. GAS' syntax is not this ambiguous.
And like Bewing said, LEA calculates the offset only. Segment registers are used only when actually accessing memory.
And like Bewing said, LEA calculates the offset only. Segment registers are used only when actually accessing memory.
Re: Question for addressings like [ebp*2+edx+50]
General Programming forum, at the very least