简体   繁体   English

装配循环

[英]Loops in Assembly

I'm kind of a rookie at programming in Assembly, and I need some clarification on the following kind of loops (@@, @B, @F). 我是Assembly编程方面的新手,我需要对以下几种循环(@@,@ B,@ F)进行一些说明。

When you have a routine like this: 当您有这样的例程时:

Routine: PROC  Value: Byte
         MOV   ECX, 3
         MOVZX EDX, Value
         MOV   EAX, EDX
     @@: SHL   EAX, 8
         OR    EAX, EDX
         LOOP @B
         RET
Routine: ENDP

, what do the @@, @B mean? ,@@,@B是什么意思?

As I was told those kinds of loops have some particularities. 有人告诉我,这些循环有一些特殊性。 @B points to the first @@ in the routine and @F points to the last @@ in the routine, am I right? @B指向例程中的第一个@@,@ F指向例程中的最后一个@@,对吗? Is there anything else regarding these loops that I should know of? 关于这些循环,还有其他我应该知道的吗? (I was also told that whenever they appear the loop goes 3 times, but I'm not sure about that). (还告诉我,每当它们出现时,循环就会循环3次,但我不确定。)

Thanks in advance. 提前致谢。

@@ is a local label. @@是本地标签。 You can put it on any code line in your program. 您可以将其放在程序中的任何代码行上。 It is valid until you define the next @@ label. 在定义下一个@@标签之前,它是有效的。 (Not the "first" or "last", just previous and next). (不是“第一个”或“最后一个”,只是前一个和下一个)。

@b means "the previously (early source line) defined @@ label". @b表示“先前(早期的源代码行)定义的@@标签”。 @f means "the next defined @@ label". @f表示“下一个定义的@@标签”。

The loop executes three times because the "LOOP" instruction decrements ECX (implicitly) on each iteration, and branches if the remaining value in ECX is not zero... and you loaded ECX with the value of 3 initially. 循环执行3次,因为“ LOOP”指令在每次迭代中都会使ECX(隐式地)递减,并且如果ECX中的剩余值不为零,则分支,并且您最初以3的值加载了ECX。

If you want to understand how the code works, you should assemble it using the MS Assembler, and then single step through it, looking at the registers as you go. 如果您想了解代码的工作原理,则应使用MS汇编器对其进行汇编,然后逐步浏览并查看寄存器。 Alternatively, read the Intel insturction set manually really carefully. 另外,请认真仔细地手动阅读英特尔指令集。 (I did a lot of this when I first started programming the x86, and it was worth every minute, even for that huge document). (当我第一次开始对x86进行编程时,我做了很多事情,即使是那份庞大的文档,它每一分钟都是值得的)。

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

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