除法导致括号不平衡

Division causes unbalanced parentheses

在 GNU as(GNU 汇编程序)中,以下代码无误地汇编:

mov $(80 * 24 + 4), %cx

但是,这段代码不会:

mov $(80 * 24 / 4), %cx

发出非常意外的错误:

example.S: Assembler messages:
example.S:42: Error: unbalanced parenthesis in operand 1.

唯一不同的是后者用的是除法,而不是加法。这应该是有效的,according to the manual.

($<expression> 将一个立即数嵌入到组装输出中;即,一个常量。算术在 "compile-time" 处执行。我可以算出数学,但它的扩展更有意义形式。)

/ 表示评论的开始,在我的特殊情况下。

--divide

On SVR4-derived platforms, the character / is treated as a comment character, which means that it cannot be used in expressions. The --divide option turns / into a normal character. This does not disable / at the beginning of a line starting a comment, or affect using # for starting a comment.

This post on the binutils mailing list 也暗示了一个类似的故事:

For compatibility with other assemblers, '/' starts a comment on the i386-elf target. So you can't use division. If you configure for i386-linux (or any of the bsds, or netware), you won't have this problem.

我碰巧正在为 x86_64-elf 目标进行组装,我认为它与提到的 i386-elf 非常相似(前者是针对 amd64 或“x86_64" arch,后者是相同的,但适用于较旧的 32 位 x86 架构。