LOOP指令的翻译问题 不用官方专业的术语把这两段翻译出来,单词会但是连不起来啊
Performs a loop operation using the ECX or CX register as a counter. Each time the LOOP instruction is executed, the count register is decremented, then checked for 0. If the count is 0, the loop is terminated and program execution continues with the instruction following the LOOP instruction. If the count is not zero, a near jump is performed to the destination (target) operand, which is presumably the instruction at the beginning of the loop. If the address-size attribute is 32 bits, the ECX register is used as the count register; otherwise the CX register is used.The target instruction is specified with a relative offset (a signed offset relative to the current value of the instruction pointer in the EIP register). This offset is generally specified as a label in assembly code, but at the machine code level, it is encoded as a signed, 8-bit immediate value, which is added to the instruction pointer. Offsets of ?28 to +127 are allowed with this instruction. 简单翻译一下,不一定准确。
执行一个 LOOP 操作用 ECX 或 CX 寄存器做为计数器,每次 LOOP 指令执行时,
计数器的值减1,然后检测计数器是否为0,如果为0,那么循环结束,程序接下来
执行跟在LOOP指令后面的指令。如果计数器不为0,则执行一个到循环开始语句
的近程跳转(这里有点拗口,不直译了)。如果地址是32位的,用ECX寄存器作为
计数器,否则用CX寄存器作为计数器
目标指令是用一个相对偏移来指定的(一个有符号的相对于当前指令地址的偏移地址【相当拗口】),
这个偏移在汇编代码里用一个语句标号来表示,但是在机器代码里,它被编码为一个
8位的有符号立即数,加在LOOP指令的地址上。它的允许值范围在-128 - +127
本帖最后由 xieglt 于 2016-10-27 17:39 编辑
一个简单的测试
_start:
XOR ECX,ECX
INC ECX
_Begin:
DB 126DUP(090H)
LOOP _Begin
看 DB 126 DUP(090H)这一条,如果把126变成127,编译就会出错
如果写成
LOOP _Begin
DB 127 DUP(90H)
_Begin:
则编译通过,把127改成128又不行了。(当然,循环没有这种写法)
看反编译的结果
图片1中是循环开始的地址是 0X00401003
图片2中是循环结束的地址是 0X00401083
0X00401003 - 0X00401083 = - 080H = -128
也就是说,循环体最大只能是126个字节,因为LOOP指令占2个字节。
页:
[1]