3 ms·
> Immediates require $, but that's the same as the Intel syntax. No, "$" is not needed (or even allowed) for immediates in Intel syntax.
by jwilk 6y ago
> Immediates require $, but that's the same as the Intel syntax.
No, "$" is not needed (or even allowed) for immediates in Intel syntax.
- adrian_b 6y agoAny assembly language needs to distinguish between immediate values and addresses. So you need a prefix on one of them, unless you use different mnemonics for the same operation, depending on whether it uses an immediate value or a memory operand. Doubling the number of operation mnemonics is clearly worse than having a single prefix. The prefix should be required for the less frequent case, and that is normally the use of immediate values. The Intel syntax as seen in the Intel architecture manuals is somewhat simplified, because it does not contain symbols and expressions. The complete assembly language syntax, for example the one implemented by the Microsoft MASM, needs frequently to distinguish the immediate values. Because MASM followed the Intel manuals, it did not use a prefix on immediate values but instead it used ugly and verbose prefixes on the memory operands, e.g. "WORD PTR ". In order to avoid excessive verbosity, MASM omitted the memory operand prefix in many cases where immediate values could not be used, which is possible only because the Intel instruction set is much less orthogonal than almost any other instruction set. Always using a prefix to distinguish immediate values from addresses is preferable to the inconsistent MASM method, because it can be tricky to remember which instructions can or cannot have both immediate operands and memory operands, so that the prefix is mandatory. Moreover, later ISA extensions could also change the available addressing modes for an operation, possibly mandating the use of the prefix. In conclusion, the MASM way of distinguishing the immediate values, by using "WORD PTR ", "BYTE PTR " and other similar prefixes on many but not all of the memory operands is certainly worse than always using the prefix "$" on immediate values.
- gliptic 6y agoWORD PTR etc. are size prefixes that would be needed even with some $-prefix for immediate values. I don't see the connection. Immediates and memory operands are already distinguished by []. The equivalent to WORD PTR etc. in AT&T syntax is the size-suffixes on instructions (addl, addw etc.).