在 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>
将一个立即数嵌入到汇编输出中;即,一个常量。算术是在“编译时”执行的。我可以算出数学,但它的扩展形式更有意义。)
最佳答案
/
在我的特殊情况下,表示评论的开始。
--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
”架构,后者是相同的,但适用于较旧的 32 位 x86 架构)。
关于assembly - 除法导致括号不平衡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38548440/