Keil™, An ARM® Company

Technical Support

A51: LOCATING VARIABLES IN ASSEMBLY 2

QUESTION

How do I locate variables without a specific address in 8051 assembly?

ANSWER

There are a number of ways to locate variables without a specific address. One could use EQU or SET, though these simply assign a numeric value or register symbol to the specified symbol name, and are not truly variables. For example:

VALUE SET 100
VALUE SET VALUE / 2
COUNT EQU  R5

In order to truly declare a variable, space must be reserved via DBIT or DS. These reserve a specified amount of memory in the currently active segment (controlled via the SEGMENT directive) For example:

FOO:    DBIT    1                                               ; reserve 1 bit under label FOO
BAR:    DS      4                                               ; reserve 4 bytes under label BAR

An additional group of assembler directives that come in handy, in this case, are BIT, CODE, DATA, IDATA, and XDATA. These assign an address value to the specified symbol. For example:

CTRL:                   DS              1                                               ; a 1 byte variable
ALARM           BIT             CTRL.0                  ; first bit in the relocatable byte CTRL
SHUT                    BIT             ALARM+1         ; the next bit

or,

DTIM:                   DS                              6
TIME                    XDATA           DTIM + 0
DATE                    XDATA           DTIM + 3

Full explanation and examples may be found in the A51 Assembler manual, chapter 4.

Last Reviewed: Monday, June 07, 2004


Did this article provide the answer you needed?
 
Yes
No