25.6. Constants

A constant is a number, written so that its value is known by inspection, without knowing any context. Like this:

.byte  74, 0112, 092, 0x4A, 0X4a, 'J, '\J # All the same value.
.ascii "Ring the bell\7"                  # A string constant.
.octa  0x123456789abcdef0123456789ABCDEF0 # A bignum.
.float 0f-314159265358979323846264338327\
95028841971.693993751E-40                 # - pi, a flonum.

25.6.1. Character Constants

There are two kinds of character constants. A character stands for one character in one byte and its value may be used in numeric expressions. String constants (properly called string literals) are potentially many bytes and their values may not be used in arithmetic expressions.

25.6.1.1. Strings

A string is written between double-quotes. It may contain double-quotes or null characters. The way to get special characters into a string is to escape these characters: precede them with a backslash "\" character. For example "\\" represents one backslash: the first \ is an escape that tells the assembler to interpret the second character literally as a backslash (which prevents the assembler from recognizing the second \ as an escape character). The complete list of escapes follows.

\b

Mnemonic for backspace; for ASCII this is octal code 010.

\f

Mnemonic for FormFeed; for ASCII this is octal code 014.

\n

Mnemonic for newline; for ASCII this is octal code 012.

\r

Mnemonic for carriage-Return; for ASCII this is octal code 015.

\t

Mnemonic for horizontal Tab; for ASCII this is octal code 011.

. digit digit digit

An octal character code. The numeric code is 3 octal digits. For compatibility with other UNIX systems, 8 and 9 are accepted as digits: for example, \008 has the value 010, and \009 the value 011.

\x hex-digits...

A hex character code. All trailing hex digits are combined. Either upper or lower case x works.

\\

Represents one "\" character.

\"

Represents one """ character. Needed in strings to represent this character, because an un-escaped """ would end the string.

. anything-else

Any other character when escaped by \ gives a warning, but assembles as if the "\" was not present. The idea is that if you used an escape sequence you clearly didn't want the literal interpretation of the following character. However, the assembler has no other interpretation, so the assembler knows it is giving you the wrong code and warns you of the fact.

Which characters are escapable, and what those escapes represent, varies widely among assemblers. The current set is what we think the BSD 4.2 assembler recognizes, and is a subset of what most C compilers recognize. If you are in doubt, do not use an escape sequence.

25.6.1.2. Characters

A single character may be written as a single quote immediately followed by that character. The same escapes apply to characters as to strings. So if you want to write the character backslash, you must write '\\ where the first \ escapes the second \. As you can see, the quote is an acute accent, not a grave accent. A newline immediately following an acute accent is taken as a literal character and does not count as the end of a statement. The value of a character constant in a numeric expression is the machine's byte-wide code for that character. the assembler assumes your character code is ASCII: 'A means 65, 'B means 66, and so on.

25.6.2. Number Constants

The assembler distinguishes three kinds of numbers according to how they are stored in the target machine. Integers are numbers that would fit into an int in the C language. Bignums are integers, but they are stored in more than 32 bits. Flonums are floating point numbers, described below.

25.6.2.1. Integers

A binary integer is "0b" or "0B" followed by zero or more of the binary digits "01".

An octal integer is "0" followed by zero or more of the octal digits ("01234567").

A decimal integer starts with a non-zero digit followed by zero or more decimal digits ("0123456789").

A hexadecimal integer is "0x" or "0X" followed by one or more hexadecimal digits chosen from "0123456789abcdefABCDEF".

To denote a negative integer, use the prefix operator - discussed under expressions (see Section 28.2.3).

25.6.2.2. Bignums

A bignum has the same syntax and semantics as an integer except that the number (or its negative) takes more than 32 bits to represent in binary. The distinction is made because in some places integers are permitted while bignums are not.

25.6.2.3. Flonums

A flonum represents a floating point number. The translation is indirect: a decimal floating point number from the text is converted by the assembler to a generic binary floating point number of more than sufficient precision. This generic floating point number is converted to a particular computer's floating point format (or formats) by a portion of the assembler specialized to that computer.

A flonum is written by writing (in order)

  • The digit "0".

  • A letter, to tell the assembler the rest of the number is a flonum. e is recommended. Case is not important.

  • An optional sign: either "+" or -.

  • An optional integer part: zero or more decimal digits.

  • An optional fractional part: "." followed by zero or more decimal digits.

  • An optional exponent, consisting of:

    • An "E" or "e".

    • Optional sign: either "+" or -.

    • One or more decimal digits.

At least one of the integer part or the fractional part must be present. The floating point number has the usual base-10 value.

The assembler does all processing using integers. Flonums are computed independently of any floating point hardware in the computer running the assembler.