鱼C论坛

 找回密码
 立即注册
查看: 2587|回复: 2

LOOP指令的翻译问题 不用官方专业的术语把这两段翻译出来,单词会但是连不起来啊

[复制链接]
发表于 2016-10-26 21:00:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-10-27 17:11:23 | 显示全部楼层
简单翻译一下,不一定准确。
执行一个 LOOP 操作用 ECX 或 CX 寄存器做为计数器,每次 LOOP 指令执行时,
计数器的值减1,然后检测计数器是否为0,如果为0,那么循环结束,程序接下来
执行跟在LOOP指令后面的指令。如果计数器不为0,则执行一个到循环开始语句
的近程跳转(这里有点拗口,不直译了)。如果地址是32位的,用ECX寄存器作为
计数器,否则用CX寄存器作为计数器
目标指令是用一个相对偏移来指定的(一个有符号的相对于当前指令地址的偏移地址【相当拗口】),
这个偏移在汇编代码里用一个语句标号来表示,但是在机器代码里,它被编码为一个
8位的有符号立即数,加在LOOP指令的地址上。它的允许值范围在-128 - +127
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-10-27 17:29:34 | 显示全部楼层
本帖最后由 xieglt 于 2016-10-27 17:39 编辑

一个简单的测试

_start:
     XOR   ECX,ECX
     INC    ECX
_Begin:
     DB   126  DUP(090H)
     LOOP   _Begin

看 DB 126 DUP(090H)  这一条,如果把126变成127,编译就会出错
如果写成

        LOOP        _Begin
        DB        127        DUP(90H)
_Begin:
则编译通过,把127改成128又不行了。(当然,循环没有这种写法)


看反编译的结果
111222.JPG
222111.JPG

图片1中是循环开始的地址是 0X00401003
图片2中是循环结束的地址是 0X00401083
0X00401003 - 0X00401083 = - 080H = -128
也就是说,循环体最大只能是126个字节,因为LOOP指令占2个字节。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 16:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表