Subj : Inline Assembler bug with structs of certain size To : borland.public.cpp.borlandcpp From : Jeremy Date : Thu Dec 02 2004 03:51 pm I found an interesting bug in the BC5.0B inline assembler today (after a couple of days tracking it down). I mention it here because it may still exist in newer versions. I have a large struct holding state information for a number of output objects. The other day I added a new member to the struct & all of a sudden my code (for an embedded 80188 CPU in a fire alarm panel) started mysteriously crashing soon after power-up. I eventually traced the problem to the fact that a couple of code fragments using inline assembler weren't working any more (were trashing system RAM instead of clearing elements in the struct). It turns out that my old structure (prior to the new element) was 19928 bytes long & the new one is 19932. I found that once you get over 19930 (it works OK again if you're above 20253!) the inline assembly statements using the structure address simply don't generate code! The following code illustrates the problem nicely: -------------------------------------------- #include static struct { char Data[19930]; // OK // char Data[19931]; // Bad // char Data[20253]; // Bad // char Data[20254]; // OK } TestStruct1; static struct { // char Data[19930]; // OK char Data[19931]; // Bad // char Data[20253]; // Bad // char Data[20254]; // OK } TestStruct2; unsigned asm_test1(void) { asm { mov ax,OFFSET TestStruct1 } return _AX; } unsigned asm_test2(void) { asm { mov ax,OFFSET TestStruct2 } return _AX; } void main(void) { printf("length of asm_test1 = %u\n", (unsigned)asm_test2 - (unsigned)asm_test1); _AX = 0xEEEE; printf("&TestStruct1 = %04x, via asm = %04x\n", &TestStruct1, asm_test1()); printf("length of asm_test2 = %u\n", (unsigned)main - (unsigned)asm_test2); _AX = 0xEEEE; printf("&TestStruct2 = %04x, via asm = %04x\n", &TestStruct2, asm_test2()); } -------------------------------------------- This code generates the following result: length of asm_test1 = 4 &TestStruct1 = 0882, via asm = 0882 length of asm_test2 = 1 &TestStruct2 = 565c, via asm = eeee The generated code for the asm_test2() function ends up being a simple RET instruction! It seems to be pretty much independent of memory model & optimizations. I need the code to be in assembler for speed, & preferably near code (I use large memory model in my app), as the code is called frequently using a number of module-local variables. Any ideas for a workaround? Thanks in advance, Jeremy .