Keil Logo

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 9, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.