ARM Technical Support Knowledge Articles

DECLARING 2 VARIABLES AT THE SAME ADDRESS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I need to declare 2 variables at the same address. What's the best way to do this?

ANSWER

  1. In your C code, create external definitions for the variables. For example:
    extern unsigned char xdata var1;
    extern unsigned char xdata var2;
    
  2. Create an assembler module that appears as follows:
    xseg at 0x8000
    
    public var1
    public var2
    
    var1:
    var2: DS 1
    
    end
    

    This creates var1 and var2 as 1-byte variables (char or unsigned char) in XDATA at address 0x8000. If you don't want or need to fix the address of the variables, you may create a relocatable segment. For example:

    xdata_junk segment xdata
    rseg xdata_junk
    
    public var1
    public var2
    
    var1:
    var2: DS 1
    
    end
    

Article last edited on: 2005-07-09 09:53:43

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