> Some examples of PIC assembly-language techniques that I > could not find a > suitable substitute for in the then 'state-of-the-art' C > compilers were: > > 1). Dispatch tables ... jumping to a handler based on the > contents of a > register: > > TRANSMIT MOVLW HIGH TXJMPTBL > MOVWF PCLATH > MOVF TX_STATE,W > ADDLW LOW TXJMPTBL > BTFSC ALUSTA,C > INCF PCLATH,F > MOVWF PCL > > TXJMPTBL GOTO TX_0 > GOTO TX_1 > GOTO TX_2 > etc ... > > TX_0 ... (handler for transmit state 0) > TX_1 ... (handler for transmit state 1) > etc ... > > This is something I definitely expected the C compilers to at > least come > close to supporting but was disappointed by ... in ANSI C the > following > would work in a similar fashion (using more stack space but > otherwise doing > the same thing): > > function protocols and table declaration: > > void tx_1(void); > void tx_2(void); > void tx_3(void); > etc... > > void (*tx_functions[]) (void) = > { > tx_1, > tx_2, > tx_3, > etc... > }; > > then, to do the dispatch: > tx_functions[tx_state](); > > > But, unfortunately the compilers I had available back then > would not do > this. I do exactly this with Hi-Tech C. Well okay, not exactly, the functions have a single parameter as well. > 2). Jumping to a common function entry or cleanup point to > save ROM space > and stack levels: > > DO_ONE_THING BSF PORTC,3 > GOTO DO_THING > > DO_SIMILAR_THING BCF PORTA,0 > > DO_THING ... > (common code) > RETURN I see my compiler doing that a lot. It really screws up source level debugging, but I appriciate the memory it saves. > 3). Tightly controlling timing by counting clock cycles and > balancing all > branches of a loop so that its cycle timing is constant. I don't think there are even directives that tell a compiler to try this. > 4). Avoiding the per-call bank switching ROM space overhead > for calling > functions in other pages of ROM by placing hooks in the same > bank as the > caller and making the hooks flip the bank select bits. Do > modern compilers > automatically do this upon request (a "save memory" versus "save time" > optimization)? It seems like they should but the ones I used > a few years > ago didn't. They would always produce code like: > BSF PCLATH,n > CALL FUNC_IN_HIGH_BANK > BCF PCLATH,n > regardless of how many times a call to that function occurred. That's on my fantasy list. Maybe this will catch someone's attention. -Mike