简体   繁体   English

汇编x86 MASM循环分析

[英]Assembly x86 MASM loop analysis

The following is a piece of loop code I am trying analyze and understand how loops work: 以下是我正在尝试分析并理解循环如何工作的循环代码:

;the ecx register is the loop counter

  mov ecx,6
  mov edx, offset space 
myloop:
  mov eax,ecx
  dec eax
  call writedec 
  call writestring 
loop myloop 
  call crlf 

  mov ecx,6
  mov edx, offset space 
myloop2:
  mov eax,6
  sub eax, ecx 
  call writedec
  call writestring 
loop myloop2

My questions are: 我的问题是:

  1. What does offset space mean? offset space意味着什么?
  2. What does mov edx, offset space mean? mov edx, offset space是什么意思?
  3. I don't understand how the offset space is the source? 我不明白offset space是如何来源的?
  4. How do you move register ecx into register eax ? 如何将寄存器ecx移动到寄存器eax
  5. Why is the offset space the source and register edx the destination? 为什么offset space是源并将edx注册到目的地?

Thank you so much for all your help. 非常感谢您的帮助。

The offset operator returns the offset of a memory location relative to the beginning of the segment (DS in the case of MOV ) to which the location belongs (see here ). offset运算符返回内存位置相对于该位置所属的段的开头(在MOV的情况下为DS)的偏移量(参见此处 )。 space is likely a variable that's defined somewhere earlier in the code, so that offset space would return the number of bytes relative to the beginning of the segment (usually the DS data segment) to that variable. space可能是在代码中较早的某处定义的变量,因此offset space将相对于段的开头(通常是DS数据段)返回到该变量的字节数。

In other words, mov edx, offset space will copy a pointer to the space variable (of type DWORD , 32-bit) to be placed in the edx register. 换句话说, mov edx, offset space将复制一个指向space变量( DWORD类型,32位)的指针放在edx寄存器中。 The reason it's placed in edx must be found in the writedec and writestring routines. 必须在writedecwritestring例程中找到它放在edx中的writedec

As for the loop you're asking about, that's where the ecx register comes in. The loop instruction will cause the code pointer to move to its destination as long as ecx is not zero, decreasing it by 1 immediately before checking it. 至于你要问的循环,这就是ecx寄存器的用武之地。只要ecx不为零, loop指令就会使代码指针移动到目的地,在检查之前立即将它减少1。 The loop value is also used by your code somewhere, which is why it's copied to eax so that other code will not change the value of ecx and mess up your loop. 你的代码也会在某处使用循环值,这就是为什么它被复制到eax以便其他代码不会改变ecx的值并弄乱你的循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM