Difference between LEA and offset in assembly X86

This question arises in the mind of every student who studies assembly X86, what is the Difference between LEA and offset?
Well, you can use them to do the same thing but, LEA
will always be better if the address is a little complex.
consider that you have the following array of chars:
ASC_TBL DB '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
if you want to get the 6th element ‘5’ you would do something like this using offset
:
mov ax, offset ASC_TBLadd ax, 5h; flags [PF] will be affected
On the other hand, if you are using the LEA
the instruction you can simply use one instruction like this:
LEA ax, [ASC_TBL + 5h]; no flags are affected
Notice that:
- Although using
LEA
proved that it has an advantage over usingoffset
, it's more efficient to useoffset
if the address isn't very complex to write or both of them will do the same thing with the same number of instructions. The reason is thatoffset ASC_TBL
is calculated during translation - like being be preprocessed- but,LEA
is an actual processor instruction. - you can’t use the
offset
instruction to get the addresses that aren't known before the compilation time.
Stackademic 🎓
Thank you for reading until the end. Before you go:
- Please consider clapping and following the writer! 👏
- Follow us X | LinkedIn | YouTube | Discord
- Visit our other platforms: In Plain English | CoFeed | Differ
- More content at Stackademic.com