We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi All, I'm having a real hard time coming up with a reason why using a local var as an index into a struct fails but that same line with an immediate value specified works properly. Here's what I mean..
void main(void) { unsigned char cTemp, cValue; // Do whats required to get under way. //---------------------------------------------------------------------------- MAIN_System_Init(); // Endless While loop that the micro runs forever (hopefully). //---------------------------------------------------------------------------- while(gcTRUE) { cValue = 0x0C; cTemp = *port[0x0C].lsr; cTemp = *port[0x0C].txrx; cTemp = *port[cValue].lsr; cTemp = *port[cValue].txrx; } }
I just compiled the following:
unsigned char lsr = 12; unsigned char txrx = 34; struct ct_st { unsigned char *lsr; unsigned char *txrx; }; volatile struct ct_st port [] = { { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, { &lsr, &txrx }, }; void main(void) { unsigned char cTemp, cValue; // Do whats required to get under way. //---------------------------------------------------------------------------- // MAIN_System_Init(); // Endless While loop that the micro runs forever (hopefully). //---------------------------------------------------------------------------- while(1) { cValue = 0x0C; cTemp = *port[0x0C].lsr; cTemp = *port[0x0C].txrx; cTemp = *port[cValue].lsr; cTemp = *port[cValue].txrx; } }
; FUNCTION main (BEGIN RMASK = @0x4022) ; SOURCE LINE # 33 ; SOURCE LINE # 34 ; SOURCE LINE # 44 0000 ?C0003: ; SOURCE LINE # 46 ; SOURCE LINE # 48 0000 F2F13000 R MOV R1,port+030H 0004 A9A1 MOVB RL5,[R1] ;---- Variable 'cTemp' assigned to Register 'RL5' ---- ; SOURCE LINE # 49 0006 F2F13200 R MOV R1,port+032H 000A A9A1 MOVB RL5,[R1] ; SOURCE LINE # 51 000C F2F13000 R MOV R1,port+030H 0010 A9A1 MOVB RL5,[R1] ; SOURCE LINE # 52 0012 F2F13200 R MOV R1,port+032H 0016 A9A1 MOVB RL5,[R1] ; SOURCE LINE # 54 0018 0DF3 JMPR cc_UC,?C0003 ; FUNCTION main (END RMASK = @0x4022)