Technical Support

C51: DECLARING 2 VARIABLES AT THE SAME ADDRESS


Information in this article applies to:

  • C51 All Versions

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
    

Last Reviewed: Saturday, July 09, 2005


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