This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Trouble overlaying 'global' variables....

Hi,

I'm working on a project that has a branch right at the start of main, so the software is essentially split into two complete sections, neither of which will ever be running at the same time. We've created the right root segments and things for overlay analysis, but there are a bunch of global or module variables that are all exclusive. How can I efficiently overlay them? I get a bit lost with the overlay controls because this is not for variables contained within functions, and they are not code segments, so how can I tell the linker in the right way to overlay them? I'm thinking that the best way to do this is to define two different memory segments for the xdata, and locate them at the same starting address.

eg.

File 1:
just one or two globals variables;

main()
{ if (a == 0) { branchA(); } else { branchB(); }
}

file A1, A2, A3, etc:
Some global variables Ag1, Ag2, Ag3, Agx etc used only by funcs in file Ax
lots of module variables;

branchA(void)
{ Lots of funcs and stuff from files A2, A3 etc
}

file B1, B2, B3, etc:
Some global variables Bg1, Bg2, Bg3, Bgx etc used only by funcs in files Bx
lots of module variables;

branchB(void)
{ Lots of funcs and stuff from files B2, B3 etc
}

How can I make sure that the linker overlays all of the memory usage for variables Agx with the memory for Bgx? I'm thinking that the best way to do this is to define two different memory segments for the xdata, and locate them at the same starting address. Correct?

Many Thanks,

Robbie.

  • have all global variables in an assembler module and declared public there, have the same variables declared extern in the .h module.

    The assembler does, as opposed to the compiler, allow you to do 'bad' things.

    example
    GlobalCharForBranch1: ds 0
    GlobalCharForBranch2: ds 1

    will overlay the two

    Maybe a more elegant way exist, but this works

    Erik

  • have all global variables for branch 1 in a struct Branch1struct and all global variables for branch 2 in a struct Branch2struct.

    then your .h will be
    extern Branch1struct b1
    extern Branch2struct b2

    the assembler module would be
    b1: ds 0
    b2: ds sizeof_the_largest_struct

    Maybe a more elegant way exist, but this works

    Erik