Instruction 1:
LEA DX, MESSAGE ; Move the address of MESSAGE in register DX
Instruction 2:
MOV DX, OFFSET MESSAGE ; Move the address of MESSAGE in register DX
Questions:
- Are the above instructions equal? They seem to work similarly, but I have just started programming assembly so I can not say.
- If both of them are similar, then which one of above is the better way to do the above task?
Note: I have already read this question
On my 32-bit system, the instructions match opcodes like this:
So you use a whole extra byte when the code is loaded into memory if you use
lea
.I found a reference to AMD chips at one point having lower latency for
lea
than formov
, but only by one clock cycle (and this will be immaterial if the data is not in L1 cache). I am not sure if that result holds for recent processors.I have found
lea
useful when trying to add an offset to a base address like this:whereas I can't do this:
and this produces the wrong result:
at least in my assembler (GNU as).