Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Elements of Assembly Language

This section describes the basic building blocks of an assembly language program—these are characters, symbols, labels, and constants.

In this section:

Characters
Identifiers
Labels
Constants
Assembly Location Counter


Characters

The following characters are used in assembly language programs:

Some of these characters have special meanings, which are described in “Expression Syntax” and in “Assembly Language Statements.”

Identifiers

An identifier (also known as a symbol) can be used for several purposes:

Each identifier consists of a sequence of alphanumeric characters (which may include other printable ASCII characters such as ., _, and $). The first character must not be numeric. Identifiers may be of any length, and all characters are significant. The case of letters is significant—for example, the identifier var is different from the identifier Var.

It is also possible to define an identifier by enclosing multiple identifiers within a pair of double quotation marks. For example:

"Object +new:":
.long "Object +new:"

Labels

A label is written as an identifier immediately followed by a colon (:). The label represents the current value of the current location counter; it can be used in assembler instructions as an operand.

Note: You may not use a single identifier to represent two different locations.

Numeric Labels

Local numeric labels allow compilers and programmers to use names temporarily. A numeric label consists of a digit (between 0 and 9) followed by a colon. These 10 local symbol names can be reused any number of times throughout the program. As with alphanumeric labels, a numeric label assigns the current value of the location counter to the symbol.

Although multiple numeric labels with the same digit may be used within the same program, only the next definition and the most recent previous definition of a label can be referenced:

The Scope of a Label

The scope of a label is the distance over which it is visible to (and referenceable by) other parts of the program. Normally, a label that tags a location or data is visible only within the current assembly unit.

The .globl directive (described in “.globl”) may be used to make a label external. In this case, the symbol is visible to other assembly units at link time.

Constants

Four types of constants are available: Numeric, character, string, and floating point. All constants are interpreted as absolute quantities when they appear in an expression.

Numeric Constants

A numeric constant is a token that starts with a digit. Numeric constants can be decimal, hexadecimal, or octal. The following restrictions apply:

Character Constants

A single-character constant consists of a single quotation mark (') followed by any ASCII character. The constant’s value is the code for the given character.

String Constants

A string constant is a sequence of zero or more ASCII characters surrounded by quotation marks (for example, "a string").

Floating-Point Constants

The general lexical form of a floating-point number is:

0flt_char[{+–}]dec...[.][dec...][exp_char[{+–}][dec...]]

where:

Item

Description

flt_char

A required type specification character (see the following table).

[{+-}]

The optional occurrence of either + or , but not both.

dec...

A required sequence of one or more decimal digits.

[.]

A single optional period.

[dec...]

An optional sequence of one or more decimal digits.

[exp_char]

An optional exponent delimiter character (see the following table).

The type specification character, flt_char, specifies the type and representation of the constructed number; the set of legal type specification characters with the processor architecture, as shown here:

Architecture

flt_char

exp_char

ppc

{dDfF}

{eE}

i386

{fFdDxX}

{eE}

When floating-point constants are used as arguments to the .single and .double directives, the type specification character isn’t actually used in determining the type of the number. For convenience, r or R can be used consistently to specify all types of floating-point numbers.

Collectively, all floating-point numbers, together with quad and octal scalars, are called bignums. When as requires a bignum, a 32-bit scalar quantity may also be used.

Floating-point constants are internally represented as flonums in a machine-independent, precision-independent floating-point format (for accurate cross-assembly).

Assembly Location Counter

A single period (.), usually referred to as “dot,” is used to represent the current location counter. There is no way to explicitly reference any other location counters besides the current location counter.

Even if it occurs in the operand field of a statement, dot refers to the address of the first byte of that statement; the value of dot isn’t updated until the next machine instruction or assembler directive.



< Previous PageNext Page > Hide TOC


Last updated: 2006-07-24




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice