Subj : Re: Inline Assembler bug with structs of certain size To : borland.public.cpp.borlandcpp From : Jeremy Date : Mon Dec 06 2004 09:47 am Hi Bob, I've found it hard to predict where BC++ decides to place pre-declared extern data in the object files. In my embedded code, I rely on lots of my configuration data (around 330K so far) staying where I initially put it, so that firmware updates can rely on the configuration data (stored in a separate Flash ROM) being where it expects. I've found the best way to ensure this is to allow 'extern' declarations anywhere, but I have a single file that contains the actual data delclarations, with all data being initialised, eg <> extern const unsigned char ConfigByte[500]; extern const TConfigStruct DeviceConfig[MAX_DEVICES]; extern const TDescriptor LocationInfo[MAX_LOCATIONS]; <> extern const TConfigStruct DeviceConfig[MAX_DEVICES] = {{0}}; extern const TDescriptor LocationInfo[MAX_LOCATIONS] = {{0}}; extern const unsigned char ConfigByte[500] = {0}; This way, I just need to ensure that the layout of 'config.c' stays the same & the linker always orders the data the same way it's listed in the file. Otherwise, the compiler seems to only allocate space for the data based on when it first "sees" that structure being used. This is a no-cost option for me, as even if the compiler generates initialisers for the data, my ROM locator software can easily ignore these when generating my ROM image file. Jeremy "Bob Gonder" wrote in message > Bob Gonder wrote: > > >Try > >> printf("&TestStruct1 = %4p, via asm = %p\n", &TestStruct1, asm_test1()); > > > >At least, on my machine, it pushes ds:address for &TestStruct1 and > >cs:value for asm_test1(). > > > >The %p properly uses the 16bit address instead of the original 4 and 4 > >(ignoring the second parameter) > > Should be 32 bit full address instead of the 2 16bit values. > > BTW, talking of shifty data..... > > Test.h > extern long Three; > extern long Two; > extern long One; > > Test.c > > #include "test.h" > long One; > long Two; > long Three; > > short Value(void) > { asm{ > mov ax, word ptr[Two+4]; > }; > return _AX; > } > > int main(void) > { > One=1; > Two=2; > Three=3; > printf( "\r\n Value=%i \r\n",Value() ); > return 0; > } > > What is the value? > Now change Test.h to > extern long One; > extern long Two; > extern long Three; > Now what is Value? > > .