[英]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: 我的问题是:
offset space
mean? offset space
意味着什么? mov edx, offset space
mean? mov edx, offset space
是什么意思? offset space
is the source? 我不明白offset space
是如何来源的? ecx
into register eax
? 如何将寄存器ecx
移动到寄存器eax
? 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. 必须在writedec
和writestring
例程中找到它放在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.