DS - Define Space

Syntax
  [<label>:]  DS[.<size>] <count>
  
  

where <size> = B (default), W, or L.

Synonym
  RMB (= DS.B)

  
  RMD (2 bytes)

  
  RMQ (4 bytes)

  
Description

The DS directive is used to reserve memory for variables, as listed in the following listing. The content of the memory reserved is not initialized. The length of the block is <size> *<count>.

<count> may not contain undefined, forward, or external references. It may range from 1 to 4096.

Listing: Examples of DS directives

Counter:  DS.B  2 ; 2 continuous bytes in memory
          DS.B  2 ; 2 continuous bytes in memory

                  ; can only be accessed through the label Counter

          DS.W  5 ; 5 continuous words in memory

The label Counter references the lowest address of the defined storage area.

Note: Storage allocated with a DS directive may end up in constant data section or even in a code section, if the same section contains constants or code as well. The Assembler allocates only a complete section at once.
Example

In the following listing, a variable, a constant, and code were put in the same section. Because code has to be in ROM, then all three elements must be put into ROM.

Listing: Poor memory allocation

; How it should NOT be done ...
Counter:        DS 1     ; 1-byte used

InitialCounter: DC.B  $f5 ; constant $f5

main:           NOP      ; NOP instruction

In order to allocate them separately, put them in different sections, as listed in the following listing:

Listing: Proper memory allocation

DataSect:      SECTION    ; separate section for variables
Counter:       DS 1       ; 1-byte used

ConstSect:     SECTION  ; separate section for constants

InitialCounter: DC.B $f5  ; constant $f5

CodeSect:      SECTION    ; section for code

main:           NOP       ; NOP instruction

An ORG directive also starts a new section.

See also