Why does following occur?
*abbreviating r= register, c = immediate value, byte value
- lea r, [r+c] ;correct as expected
- mov r, r+c ;error
- mov r, r+r ;error
- mov r, [r+c] ;correct
- mov r, [r+r] ;correct
- mov r, [c+c] ;correct
- mov r, c+c ;correct
- lea r, [c] equals mov r, c
More info:
line 2 - It is just simple calculation, right? But it can't be compiled. Also, at line 3 same problem. But at lines 4, 5, 6 and 7 MOV instruction does calculations nicely and compiler returns no error. So why does MOV fail at line 2 & 3 considering the fact that instructions at lines 2, 3 simpler than lines 4, 5 because no dereferencing done(in lines 2 and 3)?
line 8 - LEA (Load Effective Address) is supposed to calculate memory address so it should look for the address of where constant "c" stored as defined(reserved) in "section .data" and if we assume, for the sake of the scope of this question, it isn't defined or reserved there, then LEA should give a compilation error. But actually, what happens is it acts identically to MOV in this context. So, I am asking a explanation for the reason behind this strange behaviour of LEA instruction.
*I have read similar questions on "StackOverflow" regarding "difference" between "MOV" and "LEA" but they don't quite answer the situations described in this question.