2016-07-24 75 views
6

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

唯一的区别是后者使用了分割而不是广告dition。这应该是有效的,according to the manual

$<expression>嵌入立即到组装输出;即,恒定的算术在执行“编译时”我可以制定出数学,但它更有意义在其膨胀形式。)

回答

7

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

--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架构)。