8

我有一小段(x86)程序集,我试图弄清楚它的作用。

...
 6:     81 ec 00 01 00 00       sub    $0x100, %esp
 c:     31 c9                   xor    %ecx  , %ecx
 e:     88 0c 0c                mov    %cl   , (%esp, %ecx, 1)
11:     fe c1                   inc    %cl
13:     75 f9                   jne    0xe
....

它看起来像是在循环,直到“JNE”评估为假,即零标志 = 0。(可能将数字 1、2、3 ......放入堆栈??)

从我对装配的简短调查(我是新手)来看,你通过比较操作(CMP)设置了零标志,但我没有看到比较操作。

那么,在什么情况下它会跳出这个循环呢?

4

4 回答 4

12

inccl如果增量后的值为零,则设置 ZF 。您的循环正在执行此操作:

sub    $0x100, %esp            // unsigned char array[256];
xor    %ecx  , %ecx            // unsigned char cl = 0;
mov    %cl   , (%esp, %ecx, 1) // e: array[cl] = cl;
inc    %cl                     //    cl += 1;
jne    0xe                     //    if (cl != 0) goto e;

cl当从 255 递增并回绕到 0时,循环终止,设置 ZF。

于 2011-12-06T17:01:00.823 回答
8

算术指令(例如)以及add, sub, inc, dec, sar, sal按位运算(例如test, shl, shr, or, and, xor, neg等)会修改 ZF。

于 2011-12-06T18:39:41.837 回答
2

诸如 inc 和 dec 之类的数学运算也可以设置零标志。

于 2011-12-06T16:50:53.570 回答
1

或者,对于初学者,保存 [push] 堆栈上的标志,[pop] 获取寄存器中的堆栈,在寄存器上使用具有所需位的算术或运算符,压入寄存器并弹出标志。

像这样的东西。

pushf
pop ax
or ax, 0x100 [this will set trap flag, you can get the value for any flag or flags you want]
push ax
popf
于 2012-02-25T20:38:04.517 回答