本文介绍了LEA& MOV指令比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说明1:

LEA DX, MESSAGE ; Move the address of MESSAGE in register DX

说明2:

MOV DX, OFFSET MESSAGE ; Move the address of MESSAGE in register DX

问题:

  • 以上说明是否相等?它们似乎工作类似,但是我刚刚开始编程汇编,所以我不能说.
  • 如果两者相似,那么以上哪个是完成上述任务的更好方法?
  • Questions:

    • Are the above instructions equal? They seem to work similarly, but I have just started programming assembly so I can not say.
    • If both of them are similar, then which one of above is the better way to do the above task?
    • 注意:我已经阅读过此问题

      Note: I have already read this question

      推荐答案

      在我的32位系统上,指令与以下操作码匹配:

      On my 32-bit system, the instructions match opcodes like this:

      8d 15 c8 90 04 08       lea    0x80490c8,%edx
      ba c8 90 04 08          mov    $0x80490c8,%edx
      

      因此,如果使用lea,则在将代码加载到内存中时会使用整个额外的字节.

      So you use a whole extra byte when the code is loaded into memory if you use lea.

      我发现在某一点上对AMD芯片的引用对于lea的等待时间比对mov的等待时间要短,但是只有一个时钟周期(如果数据不在L1高速缓存中,则这将是无关紧要的).我不确定该结果是否适用于最近的处理器.

      I found a reference to AMD chips at one point having lower latency for lea than for mov, but only by one clock cycle (and this will be immaterial if the data is not in L1 cache). I am not sure if that result holds for recent processors.

      我发现lea在尝试向这样的基地址添加偏移量时很有用:

      I have found lea useful when trying to add an offset to a base address like this:

      lea message(,%esi,2), %ecx  # put address of message + 2 x ESI in ECX
      

      而我无法做到这一点:

      mov $message(,%esi,2), %ecx  # fails on bad syntax
      

      这会产生错误的结果:

      mov message(,%esi,2), %ecx  # puts _content_ at address, not address, into ECX 
      

      至少在我的汇编程序(GNU为)中.

      at least in my assembler (GNU as).

      这篇关于LEA& MOV指令比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:13