Data Declarations
The format for data declarations is as follows:
name: storage_type value(s)
which creates storage for variable of specified type with given name and specified value:
- A label definition consists of an identifier followed by a colon.
An identifier consists of a case-sensitive sequence of alphanumeric characters, including ‘.’, ‘_’, and ‘$’.
Identifiers can be up to 31 characters long, and the first character cannot be numeric.
- Storage types include:
- byte, halfword (2 bytes), word (4 bytes),
- a character requires 1 byte of storage, and
- an integer requires 1 word (4 bytes) of storage.
.space
gives number of spaces to be allocated.
- value(s), usually giving initial value(s), includes
- numbers entered such as 4,
- characters enclosed in single quotes such as 'b', and
- strings enclosed in double quotes such as "A string".
var1: .word 3
which creates a single integer variable with initial value 3.
array1: .byte 'a', 'b'
which creates a 2-element character array with initial values ‘a’ and ‘b’.
array2: .space 40
which allocates 40 consecutive bytes with storage uninitialized.
It could be used as a 40-element character array, or a 10-element integer array, etc.