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

When handling address in assembly 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
摘要由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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值