2016-07-24 107 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架構)。