这篇文章被朋友指出了一个最大的问题,影响了文章中提到的最重要的结论。要说清问题需要比较大的篇幅,因此另外新写了一个文章描述,请大家同时参考两个文章。另外一个文章: MASM mov指令的进一步测试
When handling address in assemble code, behavior in Windows (using MASM) and Linux (using GCC) might be totally different for the similar code. Here is a test to verify the behavior for a line of code: "mov register, variable" or "mov %register, variable". In Windows, the code move address of variable into register but in Linux, the code move the content of variable into register. To make things more complex, MASM has keyword OFFSET to PIC code and GCC is using register RIP for PIC code. So I wrote a test to check the behavior in those cases.
The code for mov in MASM not using OFFSET:
The code for mov in MASM using OFFSET:
And the disassembled code for those function using dumpbin:
From the source code and disassembled code, it comes the first conclusion:
- There is no different between adding OFFSET before variable and not adding OFFSET before variable in MASM.
- There is no different betwe