Division calls unbalanced parentheses

In GNU as (the GNU collector), the following code compiles without errors:

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

However, this code does not:

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

Radiation of a very unexpected error:

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

The only difference is that the latter uses division instead of adding. This must be valid, according to the manual .

( $<expression> embeds immediately in the collected result, that is, a constant. Arithmetic is performed at “compilation time.” I could work out the math, but it makes more sense in its extended form.)

+6
source share
1 answer

/ means start of comment in my particular case.

--divide

On platforms built on the basis of SVR4, the / symbol is considered as a comment symbol, 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 the line starting with the comment, or affects the use of # to start the comment.

This binutils mailing list post also offers a similar story:

For compatibility with other assemblers, the ' / ' begins to comment on the i386 elf. Therefore, you cannot use division. If you configure i386-linux (or any of bsds or netware), you will not have this problem.

I am going to build for the purpose x86_64-elf , which, I believe, is quite similar to the mentioned i386-elf (the former for the amd64 or " x86_64 " arch, the latter is the same, but for the old x86 32-bit architecture).

+7
source

All Articles