汇编 测试AL寄存器中的数,如果是负数转到标号NEXT去执行

2025-01-04 03:10:42
推荐回答(2个)
回答1:

AL值不变是因为TEST指令只做运算不保存与运算的结果,所以AL的内容不会变。
查一下TEST指令的相关说明就能清楚了。

回答2:

以下是芯片产生的具体到机器码的分析(简单的分析是TEST指令不影响两操作数原来内容前提下,将两数相与运算,根据结果设置标志位。为什么ADD表示加法?这是芯片产生和编译器厂商合谋产物)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TEST Logical Compare
See also
Easy Assembler Shell v3.99 Copyright(C) 1999 Roman Novgorodov
============================================================

OpcodeInstructionDescription
A8牋ibTEST AL,imm8AND imm8 with AL; set SF, ZF, PF according to result
A9 iwTEST AX,imm16AND imm16 with AX; set SF, ZF, PF according to result
A9 idTEST EAX,imm32AND imm32 with EAX; set SF, ZF, PF according to result
F6 /0 ibTEST r/m8,imm8AND imm8 with r/m8; set SF, ZF, PF according to result
F7 /0 iwTEST r/m16,imm16AND imm16 with r/m16; set SF, ZF, PF according to result
F7 /0 idTEST r/m32,imm32AND imm32 with r/m32; set SF, ZF, PF according to result
84 /rTEST r/m8,r8AND r8 with r/m8; set SF, ZF, PF according to result
85 /rTEST r/m16,r16AND r16 with r/m16; set SF, ZF, PF according to result
85 /rTEST r/m32,r32AND r32 with r/m32; set SF, ZF, PF according to result

Easy Assembler Shell v3.99 Copyright(C) 1999 Roman Novgorodov
================================================================

Description

Computes the bit-wise logical AND of first operand (source 1 operand) and the second operand (source 2 operand) and sets the SF, ZF, and PF status flags according to the result. The result is then discarded.

Operation

TEMP ?SRC1 AND SRC2;
SF ?MSB(TEMP);
IF TEMP = 0
THEN ZF ?0;
ELSE ZF ?1;
FI:
PF ?BitwiseXNOR(TEMP[0:7]);
CF ?0;
OF ?0;
(*AF is Undefined*)

Flags Affected

The OF and CF flags are cleared to 0. The SF, ZF, and PF flags are set according to the result (see the 揙peration?section above). The state of the AF flag is undefined.

Protected Mode Exceptions

#GP(0)If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
If the DS, ES, FS, or GS register contains a null segment selector.
#SS(0)If a memory operand effective address is outside the SS segment limit.
#PF(fault-code)If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.

Real-Address Mode Exceptions

#GPIf a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SSIf a memory operand effective address is outside the SS segment limit.

Virtual-8086 Mode Exceptions

#GP(0)If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SS(0)If a memory operand effective address is outside the SS segment limit.
#PF(fault-code)If a page fault occurs.
#AC(0)If alignment checking is enabled and an unaligned memory reference is made.

Easy Assembler Shell v3.99 Copyright(C) 1999 Roman Novgorodov