The other day a friend of mine asked me to code a decimal-to-hex-converter in MASM using DOS ISRs (Interrupt Service Routine) for I/O. Well, I just gave her the equivalent C code since I am not into proprietary software. But, anyway I googled for some materials related to MASM syntax and DOS ISRs for I/O [0]. Upon reading some examples of using DOS ISR 21h, I stumbled upon the use of LEA dx, var and MOV dx, OFFSET var. So, I decide to have a look into them and come up with the following conclusion.
First, the keyword OFFSET is not an x86 instruction. It is a keyword in MASM to take the address of a variable [1][2]. In C, the OFFSET keyword of MASM is the equivalent of & in, for example, scanf("%d", &var).
Second, for the simplest case of moving an address into a register, the following instructions have the same effect [3][27]:
mov dx, offset var
lea dx, var
Finally, in addition to its original purpose of doing pointer arithmetic, however, LEA can be harnessed to perform integer addition and multiplication in a way that is faster than using ADD and MUL [4] and in a way that allows the result to be stored in a register other than the source register [5].
[0] http://www.emu8086.com/assembly_language_tutorial_assembler_reference/80...
[1] http://www.posix.nl/linuxassembly/nasmdochtml/nasmdoc2.html
[2] http://www.arl.wustl.edu/~lockwood/class/cs306/course_information.html
[3] http://help-site.com/local/ASMTUT.TXT
[4] http://en.wikibooks.org/wiki/X86_Disassembly/Code_Obfuscation
[5] http://stackoverflow.com/questions/1658294/x86-asm-whats-the-purpose-of-...
[27] http://stackoverflow.com/questions/1699748/what-is-the-difference-betwee...