A Test in MASM and GCC 64-bits for instruction mov and lea

本文探讨了在Windows(使用MASM)和Linux(使用GCC)环境下,处理地址时assemble代码的行为差异。通过测试发现,MASM中`mov`指令不加`OFFSET`与加`OFFSET`行为相同,但`lea`指令会导致无法生成位置无关代码(PIC)。而在GCC中,`mov`指令会加载变量内容而非地址,需要使用`lea`指令获取地址。此外,对于局部变量、RIP寄存器的使用及32位环境下的行为也进行了讨论。
摘要由CSDN通过智能技术生成

这篇文章被朋友指出了一个最大的问题,影响了文章中提到的最重要的结论。要说清问题需要比较大的篇幅,因此另外新写了一个文章描述,请大家同时参考两个文章。另外一个文章: 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.
The code for lea in MASM:
And its disassembled code:
From the source code and disassembled code, it comes the following conclusion:
  • There is no different betwe
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值