5

So I am wondering why I cannot do this

mov eax, ffffffffh

but I can do this:

mov eax, 0ffffffffh

Could anybody explain please? In this case, I am using the Flat Assembler but I think this is not assembler-specific.

4

Most assemblers require numeric constants to begin with a digit, this is so they can distinguish between them and labels.

You can see it in FASM Fundamental syntax rules:

Numbers are distinguished from names by the fact that they either begin with a decimal digit, or with the "$" character followed by any hexadecimal digit. This means that a token can be considered numeric even when it is not a valid number. To be a correct one it must be one of the following: a decimal number (optionally with the letter "d" attached at the end), a binary number followed by the letter "b", an octal number followed by the letter "o" or "q", or a hexadecimal number either prepended with "$" or "0x", or followed by the character "h". Because the first digit of a hexadecimal number can be a letter, it may be needed to prepend it with the digit zero in order to make it recognizable as a number. For example, "0Ah" is a valid number, while "Ah" is just a name.

and in MASM Manual as well:

Hexadecimal numbers must always start with a decimal digit (0–9). If necessary, add a leading zero to distinguish between symbols and hexadecimal numbers that start with a letter.

Looking at 0ffffffffh you can see 8 significant hex digits, exactly as you'd expect. This is not unique to 0ffffffffh, another numeric literals should be written with a leading zero as well -- 0d1h, 0aah, 0b0h.

These days it is common for assemblers to support the 0xffffffff syntax. If yours is not (FLAT supports it), make sure to pay attention to the leading zero, otherwise the hexadecimal value would be interpreted as a label or another symbol name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.