assembly - 除法导致括号不平衡

标签 assembly x86 att

在 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/

相关文章:

linux - Scanf 汇编中的 char 指针

assembly - 可变位移位

c++ - 如何使用来自另一个 XMM 寄存器条目的 4 个相同 float 填充 x86 XMM 寄存器?

arrays - 如何查看已初始化数组与未初始化数组占用的内存

linux - 执行二进制文件时出现"No such file or directory"错误

c - 汇编 AT&T x86 从文件读取

c - 了解 Aleph One 的第一个缓冲区溢出漏洞

c++ - shufps 比内存访问慢吗?

c - 如何使用 GCC 在 asm() 中编写多个汇编语句而不使用 "\t\n"分隔每一行?

assembly - 不支持的指令 `lidt`