【发布时间】:2019-10-01 12:29:28
【问题描述】:
标题总结了它。
如果在调用 rcl 指令时先前设置了进位标志并且 al 为零,则最高位 (0) 不会移入进位。
以下代码演示:
mov al,0
stc
setc byte ptr [before]
rcl al,1 ; rotate left one bit through carry flag (multiply by 2 once)
setc byte ptr [after]
所以输出:
before = 01
after = 01
进位标志没有像预期的那样被清除。阅读英特尔手册:
The shift arithmetic left (SAL) and shift logical left (SHL) instructions perform the same operation; they shift the
bits in the destination operand to the left (toward more significant bit locations). For each shift count, the most
significant bit of the destination operand is shifted into the CF flag, and the least significant bit is cleared (see
Figure 7-7 in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1).
在我看来,如果源值为零,则什么都不做,这是不正确的!
【问题讨论】:
-
这在sample program 中正常工作,给我
before = 1, after = 0, al = 1。确保您的调试器在检查变量内容的最后一行之后停止。 -
您也可以使用
adc al,al作为rcl al,1的更高效替代方案。它写入所有标志,而不必合并以保留一些未修改的标志。无论如何,这看起来不像minimal reproducible example,因为问题在于您如何检查结果或其他东西。否则(不合理)您的 CPU 已损坏或(更合理)您的汇编程序已损坏。也许您在 MacOS 上存在错误的 NASM 生成不正确的寻址模式? -
最后,我在 VS2015 上进行了管理,但在使用 jwasm 移植到 VScode 时无法实现。原来我有一个 VS2015 正在避免的错误(在调用 C 代码中)。是的,所以更正了 C 代码,一切都很好,并且 rcl 正在按文档说明工作。
-
@WallyZ 酷!如果可能,请发布您的解决方案作为答案。