The error NASM gives (despite my working OS) is "invalid effective address".
Now I've seen many examples of how to use LEA and I think I got it right but yet my NASM dislikes it. I tried lea cx, [cx+9]
and it worked; lea cx, [bx+cx]
didn't.
Now if I extended my registers to 32-bits (i.e. lea ecx, [ecx*8+ecx]
) everything would be well but i am restricted to use 16- and 8-bit registers only.
Is here anyone so knowledgeable who could explain me WHY my assembler doesn't let me use lea the way I supposed it should be used?
This is because [bx+cx]
isn't valid in any addressing mode on 16-bit x86, see this site for more info.
lea cx, [bx+di]
or lea cx, [bx+si]
should work.
If your code will run on 386 or later in 16bit mode, you can use lea cx, [ecx + 9]
(address-size prefix but still 16bit operand-size).
See also this Q&A on x86 addressing modes (mostly discussing 32/64bit addressing modes, and the x86 tag wiki.
lea cx,[cx*8+cx]
doesn't work because "scale-index-base" addressing is only available with 32-bit registers. It's not a limitation of the assembler--it's a limitation of the processor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With