ARM Technical Support Knowledge Articles

LOCATING VARIABLES IN ASSEMBLY

Answer

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.

Article last edited on: 2009-02-17 06:38:50

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential