Keil™, An ARM® Company

Technical Support

A51: LOCATING VARIABLES IN ASSEMBLY

QUESTION

How do I locate variables at specific addresses in 8051 assembly?

ANSWER

There are a number of ways to locate symbols at specific addresses in assembly. Two are presented here.

One way is to use the BIT, CODE, DATA, IDATA, and XDATA assembler directives to specify the variable and the address. For example:

DATA_THING  DATA  20h

DATA_THING is replaced by 20h when you assemble your program.

The problem with this solution is that the assembler does not reserve any memory for DATA_THING and it may get overwritten by another part of your program.

Another method is to create absolute segments using the BSEG, CSEG, DSEG, ISEG, and XSEG directives. For example:

DSEG AT 40h
DATA_THING   DS 4

When you use DATA_THING, the assembler uses the address 40h. And, since we have reserved 4 bytes, the linker "knows" that the memory from 40h to 43h is already used and will avoid putting other data there.

These are just 2 of the ways you can place variables at specific locations.

SEE ALSO

Refer to the Assembler User's Guide for more information and details.

Last Reviewed: Saturday, May 08, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure