At 10:24 25/05/99 -0700, you wrote: >Hi Friends, >Has anyone come up with a decent workaround for using inline >assembly in HiTech C when the optimizer screws it up? Compiling the >assembler part to a separate module without optimizing is not really a >good option(that's the recommended thing to do, and it's stupid). > >For instance, if I want to count loops until pin 4 of PORTC drops and have >it drop through on overflow, I'd do this: > >aa1 decfsz _count > btfss 7,4 ;that's portc pin 4 > goto aa2 > goto aa1 >aa2 more stuff here... > >then the optimizer gets it's hands on it and does: >aa1 decfsz _count > btfsc 7,4 ;note btfss is now btfsc > goto aa1 > more stuff here... > >Needless to say it no longer has the timeout working. There is no "keep >hands off" directive. > >What I've been doing is adding a nop to make space and then loading the >hex code into MPLAB and patching the code back to my original. Hack! > >Anyone? > >Thanks, >Bob > > <<<<>>>>> Humm, I see what you are doing, I have used the Hitech products for quite some time now and niggly little things like this have poped up, but Hitech is not alone! I have had a look at the code that you're after and have to ask a question:- typedef struct { unsigned b7:1; unsigned b6:1; unsigned b5:1; unsigned b4:1; unsigned b3:1; unsigned b2:1; unsigned b1:1; unsigned b0:1; } SFR_BITS; /*bit structure field to bit address some things */ /************ ****begin***/ static SFR_BITS PORTA_BITS @ 0x08; /*the address of the register etc*/ #define PA7 PORTA_BITS.b7 #define PA6 PORTA_BITS.b6 #define PA5 PORTA_BITS.b5 #define PA4 PORTA_BITS.b4 #define PA3 PORTA_BITS.b3 #define PA2 PORTA_BITS.b2 #define PA1 PORTA_BITS.b1 #define PA0 PORTA_BITS.b0 What code does something like { unsigned char uc_count = 0; while (count--) { if (PA4) break; } more stuff here... } produce? you could also look at { while (PA4) { unsigend char uc_count = 0; if (!--count) break; } more stuff here... } or { for (;;) { unsigned char uc_count = 0; if (!PA4 || !--count) break; } more stuff here... } the other versions beome a little more conviluted Yes I understand that the "@" is not used by many compilers and I here the "Portability" stuff, but we are dealing with embedded code here. I must say that I do cringe when I see in-line assembly <<<<<>>>>> Badly burnt Dennis