CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

5.092 Passing struct into function can generate HUGE code.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

5.092 Passing struct into function can generate HUGE code.
PostPosted: Wed Jan 29, 2020 4:48 pm     Reply with quote

SUMMARY: Yes, I know one can pass the address of a structure and that's much more efficient. This is just a sample to show a problem with code generation...

EDIT: See also http://www.ccsinfo.com/forum/viewtopic.php?t=58491
---

We previously found a bug with accessing elements of a structure where the compiler was miscalculating the offset to the data and walking past the end of the entire structure.

I think we found another related issue. For this example, I am passing a structure (the entire structure, not a pointer) in to a function.

1) If you pass in the structure item by actual number ([0]), it generates nice small acceptable code:


Code:
....................    ShowThing (objects.things[0]);
*
00452:  MOV     #800,W0
00454:  MOV     #848,W1
00456:  REPEAT  #15
00458:  MOV     [W0++],[W1++]
0045A:  CALL    3DA
....................



2) BUT, if instead of using a hard-coded number, you are using a variable to be the index -- in this case, "n = 0;", it generates much more code:


Code:
....................    int n = 0;
*
0045E:  CLR     82E
....................    ShowThing (objects.things[n]);
00460:  MOV     82E,W4
00462:  MUL.UU  W4,#16,W0
00464:  MOV     #800,W4
00466:  ADD     W0,W4,W0
00468:  MOV     #A,W4
0046A:  REPEAT  #A
0046C:  MOV     [W0++],[W4++]
0046E:  MOV     W5,848
00470:  MOV     W6,84A
00472:  MOV     W7,84C
00474:  MOV     W8,84E
00476:  MOV     W9,850
00478:  MOV     W10,852
0047A:  MOV     W11,854
0047C:  MOV     W12,856
0047E:  MOV     W13,858
00480:  MOV     W14,85A
00482:  MOV     W15,85C
00484:  MOV     W6,84A
00486:  MOV     W7,84C
00488:  MOV     W8,84E
0048A:  MOV     W9,850
0048C:  MOV     W10,852
0048E:  MOV     W11,854
00490:  MOV     W12,856
00492:  MOV     W13,858
00494:  MOV     W14,85A
00496:  MOV     W15,85C
00498:  MOV     W0,85E
0049A:  MOV     W7,84C
0049C:  MOV     W8,84E
0049E:  MOV     W9,850
004A0:  MOV     W10,852
004A2:  MOV     W11,854
004A4:  MOV     W12,856
004A6:  MOV     W13,858
004A8:  MOV     W14,85A
004AA:  MOV     W15,85C
004AC:  MOV     W0,85E
004AE:  MOV     W1,860
004B0:  MOV     W8,84E
004B2:  MOV     W9,850
004B4:  MOV     W10,852
004B6:  MOV     W11,854
004B8:  MOV     W12,856
004BA:  MOV     W13,858
004BC:  MOV     W14,85A
004BE:  MOV     W15,85C
004C0:  MOV     W0,85E
004C2:  MOV     W1,860
004C4:  MOV     W2,862
004C6:  MOV     W9,850
004C8:  MOV     W10,852
004CA:  MOV     W11,854
004CC:  MOV     W12,856
004CE:  MOV     W13,858
004D0:  MOV     W14,85A
004D2:  MOV     W15,85C
004D4:  MOV     W0,85E
004D6:  MOV     W1,860
004D8:  MOV     W2,862
004DA:  MOV     W3,864
004DC:  MOV     W10,852
004DE:  MOV     W11,854
004E0:  MOV     W12,856
004E2:  MOV     W13,858
004E4:  MOV     W14,85A
004E6:  MOV     W15,85C
004E8:  MOV     W0,85E
004EA:  MOV     W1,860
004EC:  MOV     W2,862
004EE:  MOV     W3,864
004F0:  MOV     W4,866
004F2:  MOV     W11,854
004F4:  MOV     W12,856
004F6:  MOV     W13,858
004F8:  MOV     W14,85A
004FA:  MOV     W15,85C
004FC:  MOV     W0,85E
004FE:  MOV     W1,860
00500:  MOV     W2,862
00502:  MOV     W3,864
00504:  MOV     W4,866
00506:  MOV     W5,868
00508:  MOV     W12,856
0050A:  MOV     W13,858
0050C:  MOV     W14,85A
0050E:  MOV     W15,85C
00510:  MOV     W0,85E
00512:  MOV     W1,860
00514:  MOV     W2,862
00516:  MOV     W3,864
00518:  MOV     W4,866
0051A:  MOV     W5,868
0051C:  MOV     W6,86A
0051E:  MOV     W13,858
00520:  MOV     W14,85A
00522:  MOV     W15,85C
00524:  MOV     W0,85E
00526:  MOV     W1,860
00528:  MOV     W2,862
0052A:  MOV     W3,864
0052C:  MOV     W4,866
0052E:  MOV     W5,868
00530:  MOV     W6,86A
00532:  MOV     W7,86C
00534:  MOV     W14,85A
00536:  MOV     W15,85C
00538:  MOV     W0,85E
0053A:  MOV     W1,860
0053C:  MOV     W2,862
0053E:  MOV     W3,864
00540:  MOV     W4,866
00542:  MOV     W5,868
00544:  MOV     W6,86A
00546:  MOV     W7,86C
00548:  MOV     W8,86E
0054A:  MOV     W15,85C
0054C:  MOV     W0,85E
0054E:  MOV     W1,860
00550:  MOV     W2,862
00552:  MOV     W3,864
00554:  MOV     W4,866
00556:  MOV     W5,868
00558:  MOV     W6,86A
0055A:  MOV     W7,86C
0055C:  MOV     W8,86E
0055E:  MOV     W9,870
00560:  CALL    3DA
....................



3) But you can make a temp structure, and assign the array[n] to it and then pass in that temp and it works just fine:


Code:
....................    ThingStruct tempThing;
....................    tempThing = objects.things[n];
*
00564:  MOV     82E,W4
00566:  MUL.UU  W4,#16,W0
00568:  MOV     #800,W4
0056A:  ADD     W0,W4,W0
0056C:  MOV     #830,W1
0056E:  MOV     W0,W2
00570:  REPEAT  #15
00572:  MOV.B   [W2++],[W1++]
....................    ShowThing (tempThing);
00574:  MOV     #830,W0
00576:  MOV     #848,W1
00578:  REPEAT  #15
0057A:  MOV     [W0++],[W1++]
0057C:  CALL    3DA
....................


This is at the heart of our latest crash. We had rebooting system and it narrowed it down to passing in a structure using a variable for the index. If it's [0], [3], [5], etc... the code works fine, but the moment it's an index of a variable we get hundreds of lines of MOV code and it's apparently walking over memory somewhere and crashing the stack or something.

Anyway, this is just something fun I thought I'd share, not that many people pass in structures to functions. :-)[/url]
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?


Last edited by allenhuffman on Thu Jan 30, 2020 3:08 pm; edited 3 times in total
jeremiah



Joined: 20 Jul 2010
Posts: 1319

View user's profile Send private message

PostPosted: Wed Jan 29, 2020 6:08 pm     Reply with quote

Make sure to report it to CCS support so they can fix it.
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Wed Jan 29, 2020 7:01 pm     Reply with quote

Kind of related to a code bloat issue I faced some time back: http://www.ccsinfo.com/forum/viewtopic.php?t=56379
Ttelmah



Joined: 11 Mar 2010
Posts: 19245

View user's profile Send private message

PostPosted: Thu Jan 30, 2020 1:01 am     Reply with quote

Slightly puzzled as to the nature of the object here.

If 'objects' is an array of structures, the normal access, would be:

objects[n].things

not

objects.things[n]

as you show.

You seem to be accessing an element inside an array, that is inside a
structure, not the 'entire structure', as you describe?.
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 30, 2020 7:11 am     Reply with quote

Ttelmah wrote:
Slightly puzzled as to the nature of the object here.

If 'objects' is an array of structures, the normal access, would be:

objects[n].things

not

objects.things[n]

as you show.

You seem to be accessing an element inside an array, that is inside a
structure, not the 'entire structure', as you describe?.


Yep. It happens even with just one of them.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 30, 2020 8:25 am     Reply with quote

Here's an example that doesn't even use sub-structures. I only used that in my example because that is what we are wanting to do, so I wanted code for CCS to use that replicated the type of stuff we were using.

main.h:
Code:
#include <24FJ256GA106.h>
#device ICSP=1
#use delay(clock=32MHz,crystal=8MHz)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled

#use rs232(ICD)

#case

typedef struct
{
   char        name[100];
   int         value;
} ObjectStruct;


main.c:
Code:
#include <main.h>

#define NUM_OBJECTS 2

// Prototypes
void ShowObject (ObjectStruct object);

// Globals
ObjectStruct objects[NUM_OBJECTS];


void main()
{
   int idx;
   
   for (idx = 0; idx < NUM_OBJECTS; idx++)
   {
      objects[idx].value = (100 + idx);
   }
   
   ShowObject (objects[0]);
   
   int n = 0;
   ShowObject (objects[n]);

   while(TRUE)
   {
      //TODO: User Code
   }
}


void ShowObject (ObjectStruct object)
{
   printf ("object.value = %d\r\n", object.value);
}

// End of main.c


Results:

Code:
....................   
....................    ShowObject (objects[0]);
*
003EA:  MOV     #800,W0
003EC:  MOV     #8D2,W1
003EE:  REPEAT  #65
003F0:  MOV     [W0++],[W1++]
003F2:  CALL    378
....................   
....................    int n = 0;
*
003F6:  CLR     8CE
....................    ShowObject (objects[n]);
003F8:  MOV     8CE,W4
003FA:  MOV     #66,W3
003FC:  MUL.SS  W4,W3,W0
003FE:  MOV     #800,W4
00400:  ADD     W0,W4,W0
00402:  MOV     #A,W4
00404:  REPEAT  #32
00406:  MOV     [W0++],[W4++]
00408:  MOV     W5,8D2
0040A:  MOV     W6,8D4
0040C:  MOV     W7,8D6
0040E:  MOV     W8,8D8
00410:  MOV     W9,8DA
00412:  MOV     W10,8DC
00414:  MOV     W11,8DE
00416:  MOV     W12,8E0
00418:  MOV     W13,8E2
0041A:  MOV     W14,8E4
0041C:  MOV     W15,8E6
0041E:  MOV     W0,8E8
00420:  MOV     W1,8EA
00422:  MOV     W2,8EC
00424:  MOV     W3,8EE
00426:  MOV     W4,8F0
00428:  MOV     W5,8F2
0042A:  MOV     W6,8F4
0042C:  MOV     W7,8F6
0042E:  MOV     W8,8F8
00430:  MOV     W9,8FA
00432:  MOV     W10,8FC
00434:  MOV     W11,8FE
00436:  MOV     W12,900
00438:  MOV     W13,902
0043A:  MOV     W14,904
0043C:  MOV     W15,906
0043E:  MOV     W0,908
00440:  MOV     W1,90A
00442:  MOV     W2,90C
00444:  MOV     W3,90E
00446:  MOV     W4,910
00448:  MOV     W5,912
0044A:  MOV     W6,914
0044C:  MOV     W7,916
0044E:  MOV     W8,918
00450:  MOV     W9,91A
00452:  MOV     W10,91C
00454:  MOV     W11,91E
00456:  MOV     W12,920
00458:  MOV     W13,922
0045A:  MOV     W14,924
0045C:  MOV     W15,926
0045E:  MOV     W0,928
00460:  MOV     W1,92A
00462:  MOV     W2,92C
00464:  MOV     W3,92E
00466:  MOV     W4,930
00468:  MOV     W5,932
0046A:  MOV     W6,934
0046C:  MOV     W7,936
0046E:  MOV     W6,8D4
00470:  MOV     W7,8D6
00472:  MOV     W8,8D8
00474:  MOV     W9,8DA
00476:  MOV     W10,8DC
00478:  MOV     W11,8DE
0047A:  MOV     W12,8E0
0047C:  MOV     W13,8E2
0047E:  MOV     W14,8E4
00480:  MOV     W15,8E6
00482:  MOV     W0,8E8
00484:  MOV     W1,8EA
00486:  MOV     W2,8EC
00488:  MOV     W3,8EE
0048A:  MOV     W4,8F0
0048C:  MOV     W5,8F2
0048E:  MOV     W6,8F4
00490:  MOV     W7,8F6
00492:  MOV     W8,8F8
00494:  MOV     W9,8FA
00496:  MOV     W10,8FC
00498:  MOV     W11,8FE
0049A:  MOV     W12,900
0049C:  MOV     W13,902
0049E:  MOV     W14,904
004A0:  MOV     W15,906
004A2:  MOV     W0,908
004A4:  MOV     W1,90A
004A6:  MOV     W2,90C
004A8:  MOV     W3,90E
004AA:  MOV     W4,910
004AC:  MOV     W5,912
004AE:  MOV     W6,914
004B0:  MOV     W7,916
004B2:  MOV     W8,918
004B4:  MOV     W9,91A
004B6:  MOV     W10,91C
004B8:  MOV     W11,91E
004BA:  MOV     W12,920
004BC:  MOV     W13,922
004BE:  MOV     W14,924
004C0:  MOV     W15,926
004C2:  MOV     W0,928
004C4:  MOV     W1,92A
004C6:  MOV     W2,92C
004C8:  MOV     W3,92E
004CA:  MOV     W4,930
004CC:  MOV     W5,932
004CE:  MOV     W6,934
004D0:  MOV     W7,936
004D2:  MOV     W8,938
004D4:  MOV     W7,8D6
004D6:  MOV     W8,8D8
004D8:  MOV     W9,8DA
004DA:  MOV     W10,8DC
004DC:  MOV     W11,8DE
004DE:  MOV     W12,8E0
004E0:  MOV     W13,8E2
004E2:  MOV     W14,8E4
004E4:  MOV     W15,8E6
004E6:  MOV     W0,8E8
004E8:  MOV     W1,8EA
004EA:  MOV     W2,8EC
004EC:  MOV     W3,8EE
004EE:  MOV     W4,8F0
004F0:  MOV     W5,8F2
004F2:  MOV     W6,8F4
004F4:  MOV     W7,8F6
004F6:  MOV     W8,8F8
004F8:  MOV     W9,8FA
004FA:  MOV     W10,8FC
004FC:  MOV     W11,8FE
004FE:  MOV     W12,900
00500:  MOV     W13,902
00502:  MOV     W14,904
00504:  MOV     W15,906
00506:  MOV     W0,908
00508:  MOV     W1,90A
0050A:  MOV     W2,90C
0050C:  MOV     W3,90E
0050E:  MOV     W4,910
00510:  MOV     W5,912
00512:  MOV     W6,914
00514:  MOV     W7,916
00516:  MOV     W8,918
00518:  MOV     W9,91A
0051A:  MOV     W10,91C
0051C:  MOV     W11,91E
0051E:  MOV     W12,920
00520:  MOV     W13,922
00522:  MOV     W14,924
00524:  MOV     W15,926
00526:  MOV     W0,928
00528:  MOV     W1,92A
0052A:  MOV     W2,92C
0052C:  MOV     W3,92E
0052E:  MOV     W4,930
00530:  MOV     W5,932
00532:  MOV     W6,934
00534:  MOV     W7,936
00536:  MOV     W8,938
00538:  MOV     W9,93A
0053A:  MOV     W8,8D8
0053C:  MOV     W9,8DA
0053E:  MOV     W10,8DC
00540:  MOV     W11,8DE
00542:  MOV     W12,8E0
00544:  MOV     W13,8E2
00546:  MOV     W14,8E4
00548:  MOV     W15,8E6
0054A:  MOV     W0,8E8
0054C:  MOV     W1,8EA
0054E:  MOV     W2,8EC
00550:  MOV     W3,8EE
00552:  MOV     W4,8F0
00554:  MOV     W5,8F2
00556:  MOV     W6,8F4
00558:  MOV     W7,8F6
0055A:  MOV     W8,8F8
0055C:  MOV     W9,8FA
0055E:  MOV     W10,8FC
00560:  MOV     W11,8FE
00562:  MOV     W12,900
00564:  MOV     W13,902
00566:  MOV     W14,904
00568:  MOV     W15,906
0056A:  MOV     W0,908
0056C:  MOV     W1,90A
0056E:  MOV     W2,90C
00570:  MOV     W3,90E
00572:  MOV     W4,910
00574:  MOV     W5,912
00576:  MOV     W6,914
00578:  MOV     W7,916
0057A:  MOV     W8,918
0057C:  MOV     W9,91A
0057E:  MOV     W10,91C
00580:  MOV     W11,91E
00582:  MOV     W12,920
00584:  MOV     W13,922
00586:  MOV     W14,924
00588:  MOV     W15,926
0058A:  MOV     W0,928
0058C:  MOV     W1,92A
0058E:  MOV     W2,92C
00590:  MOV     W3,92E
00592:  MOV     W4,930
00594:  MOV     W5,932
00596:  MOV     W6,934
00598:  MOV     W7,936
0059A:  MOV     W8,938
0059C:  MOV     W9,93A
0059E:  MOV     W10,93C
005A0:  MOV     W9,8DA
005A2:  MOV     W10,8DC
005A4:  MOV     W11,8DE
005A6:  MOV     W12,8E0
005A8:  MOV     W13,8E2
005AA:  MOV     W14,8E4
005AC:  MOV     W15,8E6
005AE:  MOV     W0,8E8
005B0:  MOV     W1,8EA
005B2:  MOV     W2,8EC
005B4:  MOV     W3,8EE
005B6:  MOV     W4,8F0
005B8:  MOV     W5,8F2
005BA:  MOV     W6,8F4
005BC:  MOV     W7,8F6
005BE:  MOV     W8,8F8
005C0:  MOV     W9,8FA
005C2:  MOV     W10,8FC
005C4:  MOV     W11,8FE
005C6:  MOV     W12,900
005C8:  MOV     W13,902
005CA:  MOV     W14,904
005CC:  MOV     W15,906
005CE:  MOV     W0,908
005D0:  MOV     W1,90A
005D2:  MOV     W2,90C
005D4:  MOV     W3,90E
005D6:  MOV     W4,910
005D8:  MOV     W5,912
005DA:  MOV     W6,914
005DC:  MOV     W7,916
005DE:  MOV     W8,918
005E0:  MOV     W9,91A
005E2:  MOV     W10,91C
005E4:  MOV     W11,91E
005E6:  MOV     W12,920
005E8:  MOV     W13,922
005EA:  MOV     W14,924
005EC:  MOV     W15,926
005EE:  MOV     W0,928
005F0:  MOV     W1,92A
005F2:  MOV     W2,92C
005F4:  MOV     W3,92E
005F6:  MOV     W4,930
005F8:  MOV     W5,932
005FA:  MOV     W6,934
005FC:  MOV     W7,936
005FE:  MOV     W8,938
00600:  MOV     W9,93A
00602:  MOV     W10,93C
00604:  MOV     W11,93E
00606:  MOV     W10,8DC
00608:  MOV     W11,8DE
0060A:  MOV     W12,8E0
0060C:  MOV     W13,8E2
0060E:  MOV     W14,8E4
00610:  MOV     W15,8E6
00612:  MOV     W0,8E8
00614:  MOV     W1,8EA
00616:  MOV     W2,8EC
00618:  MOV     W3,8EE
0061A:  MOV     W4,8F0
0061C:  MOV     W5,8F2
0061E:  MOV     W6,8F4
00620:  MOV     W7,8F6
00622:  MOV     W8,8F8
00624:  MOV     W9,8FA
00626:  MOV     W10,8FC
00628:  MOV     W11,8FE
0062A:  MOV     W12,900
0062C:  MOV     W13,902
0062E:  MOV     W14,904
00630:  MOV     W15,906
00632:  MOV     W0,908
00634:  MOV     W1,90A
00636:  MOV     W2,90C
00638:  MOV     W3,90E
0063A:  MOV     W4,910
0063C:  MOV     W5,912
0063E:  MOV     W6,914
00640:  MOV     W7,916
00642:  MOV     W8,918
00644:  MOV     W9,91A
00646:  MOV     W10,91C
00648:  MOV     W11,91E
0064A:  MOV     W12,920
0064C:  MOV     W13,922
0064E:  MOV     W14,924
00650:  MOV     W15,926
00652:  MOV     W0,928
00654:  MOV     W1,92A
00656:  MOV     W2,92C
00658:  MOV     W3,92E
0065A:  MOV     W4,930
0065C:  MOV     W5,932
0065E:  MOV     W6,934
00660:  MOV     W7,936
00662:  MOV     W8,938
00664:  MOV     W9,93A
00666:  MOV     W10,93C
00668:  MOV     W11,93E
0066A:  MOV     W12,940
0066C:  MOV     W11,8DE
0066E:  MOV     W12,8E0
00670:  MOV     W13,8E2
00672:  MOV     W14,8E4
00674:  MOV     W15,8E6
00676:  MOV     W0,8E8
00678:  MOV     W1,8EA
0067A:  MOV     W2,8EC
0067C:  MOV     W3,8EE
0067E:  MOV     W4,8F0
00680:  MOV     W5,8F2
00682:  MOV     W6,8F4
00684:  MOV     W7,8F6
00686:  MOV     W8,8F8
00688:  MOV     W9,8FA
0068A:  MOV     W10,8FC
0068C:  MOV     W11,8FE
0068E:  MOV     W12,900
00690:  MOV     W13,902
00692:  MOV     W14,904
00694:  MOV     W15,906
00696:  MOV     W0,908
00698:  MOV     W1,90A
0069A:  MOV     W2,90C
0069C:  MOV     W3,90E
0069E:  MOV     W4,910
006A0:  MOV     W5,912
006A2:  MOV     W6,914
006A4:  MOV     W7,916
006A6:  MOV     W8,918
006A8:  MOV     W9,91A
006AA:  MOV     W10,91C
006AC:  MOV     W11,91E
006AE:  MOV     W12,920
006B0:  MOV     W13,922
006B2:  MOV     W14,924
006B4:  MOV     W15,926
006B6:  MOV     W0,928
006B8:  MOV     W1,92A
006BA:  MOV     W2,92C
006BC:  MOV     W3,92E
006BE:  MOV     W4,930
006C0:  MOV     W5,932
006C2:  MOV     W6,934
006C4:  MOV     W7,936
006C6:  MOV     W8,938
006C8:  MOV     W9,93A
006CA:  MOV     W10,93C
006CC:  MOV     W11,93E
006CE:  MOV     W12,940
006D0:  MOV     W13,942
006D2:  MOV     W12,8E0
006D4:  MOV     W13,8E2
006D6:  MOV     W14,8E4
006D8:  MOV     W15,8E6
006DA:  MOV     W0,8E8
006DC:  MOV     W1,8EA
006DE:  MOV     W2,8EC
006E0:  MOV     W3,8EE
006E2:  MOV     W4,8F0
006E4:  MOV     W5,8F2
006E6:  MOV     W6,8F4
006E8:  MOV     W7,8F6
006EA:  MOV     W8,8F8
006EC:  MOV     W9,8FA
006EE:  MOV     W10,8FC
006F0:  MOV     W11,8FE
006F2:  MOV     W12,900
006F4:  MOV     W13,902
006F6:  MOV     W14,904
006F8:  MOV     W15,906
006FA:  MOV     W0,908
006FC:  MOV     W1,90A
006FE:  MOV     W2,90C
00700:  MOV     W3,90E
00702:  MOV     W4,910
00704:  MOV     W5,912
00706:  MOV     W6,914
00708:  MOV     W7,916
0070A:  MOV     W8,918
0070C:  MOV     W9,91A
0070E:  MOV     W10,91C
00710:  MOV     W11,91E
00712:  MOV     W12,920
00714:  MOV     W13,922
00716:  MOV     W14,924
00718:  MOV     W15,926
0071A:  MOV     W0,928
0071C:  MOV     W1,92A
0071E:  MOV     W2,92C
00720:  MOV     W3,92E
00722:  MOV     W4,930
00724:  MOV     W5,932
00726:  MOV     W6,934
00728:  MOV     W7,936
0072A:  MOV     W8,938
0072C:  MOV     W9,93A
0072E:  MOV     W10,93C
00730:  MOV     W11,93E
00732:  MOV     W12,940
00734:  MOV     W13,942
00736:  MOV     W14,944
00738:  MOV     W13,8E2
0073A:  MOV     W14,8E4
0073C:  MOV     W15,8E6
0073E:  MOV     W0,8E8
00740:  MOV     W1,8EA
00742:  MOV     W2,8EC
00744:  MOV     W3,8EE
00746:  MOV     W4,8F0
00748:  MOV     W5,8F2
0074A:  MOV     W6,8F4
0074C:  MOV     W7,8F6
0074E:  MOV     W8,8F8
00750:  MOV     W9,8FA
00752:  MOV     W10,8FC
00754:  MOV     W11,8FE
00756:  MOV     W12,900
00758:  MOV     W13,902
0075A:  MOV     W14,904
0075C:  MOV     W15,906
0075E:  MOV     W0,908
00760:  MOV     W1,90A
00762:  MOV     W2,90C
00764:  MOV     W3,90E
00766:  MOV     W4,910
00768:  MOV     W5,912
0076A:  MOV     W6,914
0076C:  MOV     W7,916
0076E:  MOV     W8,918
00770:  MOV     W9,91A
00772:  MOV     W10,91C
00774:  MOV     W11,91E
00776:  MOV     W12,920
00778:  MOV     W13,922
0077A:  MOV     W14,924
0077C:  MOV     W15,926
0077E:  MOV     W0,928
00780:  MOV     W1,92A
00782:  MOV     W2,92C
00784:  MOV     W3,92E
00786:  MOV     W4,930
00788:  MOV     W5,932
0078A:  MOV     W6,934
0078C:  MOV     W7,936
0078E:  MOV     W8,938
00790:  MOV     W9,93A
00792:  MOV     W10,93C
00794:  MOV     W11,93E
00796:  MOV     W12,940
00798:  MOV     W13,942
0079A:  MOV     W14,944
0079C:  MOV     W15,946
0079E:  MOV     W14,8E4
007A0:  MOV     W15,8E6
007A2:  MOV     W0,8E8
007A4:  MOV     W1,8EA
007A6:  MOV     W2,8EC
007A8:  MOV     W3,8EE
007AA:  MOV     W4,8F0
007AC:  MOV     W5,8F2
007AE:  MOV     W6,8F4
007B0:  MOV     W7,8F6
007B2:  MOV     W8,8F8
007B4:  MOV     W9,8FA
007B6:  MOV     W10,8FC
007B8:  MOV     W11,8FE
007BA:  MOV     W12,900
007BC:  MOV     W13,902
007BE:  MOV     W14,904
007C0:  MOV     W15,906
007C2:  MOV     W0,908
007C4:  MOV     W1,90A
007C6:  MOV     W2,90C
007C8:  MOV     W3,90E
007CA:  MOV     W4,910
007CC:  MOV     W5,912
007CE:  MOV     W6,914
007D0:  MOV     W7,916
007D2:  MOV     W8,918
007D4:  MOV     W9,91A
007D6:  MOV     W10,91C
007D8:  MOV     W11,91E
007DA:  MOV     W12,920
007DC:  MOV     W13,922
007DE:  MOV     W14,924
007E0:  MOV     W15,926
007E2:  MOV     W0,928
007E4:  MOV     W1,92A
007E6:  MOV     W2,92C
007E8:  MOV     W3,92E
007EA:  MOV     W4,930
007EC:  MOV     W5,932
007EE:  MOV     W6,934
007F0:  MOV     W7,936
007F2:  MOV     W8,938
007F4:  MOV     W9,93A
007F6:  MOV     W10,93C
007F8:  MOV     W11,93E
007FA:  MOV     W12,940
007FC:  MOV     W13,942
007FE:  MOV     W14,944
00800:  MOV     W15,946
00802:  MOV     W0,948
00804:  MOV     W15,8E6
00806:  MOV     W0,8E8
00808:  MOV     W1,8EA
0080A:  MOV     W2,8EC
0080C:  MOV     W3,8EE
0080E:  MOV     W4,8F0
00810:  MOV     W5,8F2
00812:  MOV     W6,8F4
00814:  MOV     W7,8F6
00816:  MOV     W8,8F8
00818:  MOV     W9,8FA
0081A:  MOV     W10,8FC
0081C:  MOV     W11,8FE
0081E:  MOV     W12,900
00820:  MOV     W13,902
00822:  MOV     W14,904
00824:  MOV     W15,906
00826:  MOV     W0,908
00828:  MOV     W1,90A
0082A:  MOV     W2,90C
0082C:  MOV     W3,90E
0082E:  MOV     W4,910
00830:  MOV     W5,912
00832:  MOV     W6,914
00834:  MOV     W7,916
00836:  MOV     W8,918
00838:  MOV     W9,91A
0083A:  MOV     W10,91C
0083C:  MOV     W11,91E
0083E:  MOV     W12,920
00840:  MOV     W13,922
00842:  MOV     W14,924
00844:  MOV     W15,926
00846:  MOV     W0,928
00848:  MOV     W1,92A
0084A:  MOV     W2,92C
0084C:  MOV     W3,92E
0084E:  MOV     W4,930
00850:  MOV     W5,932
00852:  MOV     W6,934
00854:  MOV     W7,936
00856:  MOV     W8,938
00858:  MOV     W9,93A
0085A:  MOV     W10,93C
0085C:  MOV     W11,93E
0085E:  MOV     W12,940
00860:  MOV     W13,942
00862:  MOV     W14,944
00864:  MOV     W15,946
00866:  MOV     W0,948
00868:  MOV     W1,94A
0086A:  SUB     #66,W0
0086C:  MOV     #8E8,W4
0086E:  REPEAT  #32
00870:  MOV     [W0++],[W4++]
00872:  MOV     #8EA,W4
00874:  REPEAT  #32
00876:  MOV     [W1++],[W4++]
00878:  MOV     #8EC,W4
0087A:  REPEAT  #32
0087C:  MOV     [W2++],[W4++]
0087E:  MOV     #8EE,W4
00880:  REPEAT  #32
00882:  MOV     [W3++],[W4++]
00884:  MOV     #8F0,W0
00886:  REPEAT  #32
00888:  MOV     [W4++],[W0++]
0088A:  MOV     #8F2,W0
0088C:  REPEAT  #32
0088E:  MOV     [W5++],[W0++]
00890:  MOV     #8F4,W0
00892:  REPEAT  #32
00894:  MOV     [W6++],[W0++]
00896:  MOV     #8F6,W0
00898:  REPEAT  #32
0089A:  MOV     [W7++],[W0++]
0089C:  MOV     #8F8,W0
0089E:  REPEAT  #32
008A0:  MOV     [W8++],[W0++]
008A2:  MOV     #8FA,W0
008A4:  REPEAT  #32
008A6:  MOV     [W9++],[W0++]
008A8:  MOV     #8FC,W0
008AA:  REPEAT  #32
008AC:  MOV     [W10++],[W0++]
008AE:  MOV     #8FE,W0
008B0:  REPEAT  #32
008B2:  MOV     [W11++],[W0++]
008B4:  MOV     #900,W0
008B6:  REPEAT  #32
008B8:  MOV     [W12++],[W0++]
008BA:  MOV     #902,W0
008BC:  REPEAT  #32
008BE:  MOV     [W13++],[W0++]
008C0:  SUB     #CC,W14
008C2:  MOV     #904,W0
008C4:  REPEAT  #32
008C6:  MOV     [W14++],[W0++]
008C8:  SUB     #CC,W15
008CA:  MOV     #906,W0
008CC:  REPEAT  #32
008CE:  MOV     [W15++],[W0++]
008D0:  MOV     #908,W0
008D2:  REPEAT  #32
008D4:  MOV     [W0++],[W0++]
008D6:  MOV     #90A,W0
008D8:  REPEAT  #32
008DA:  MOV     [W1++],[W0++]
008DC:  MOV     #90C,W0
008DE:  REPEAT  #32
008E0:  MOV     [W2++],[W0++]
008E2:  MOV     #90E,W0
008E4:  REPEAT  #32
008E6:  MOV     [W3++],[W0++]
008E8:  MOV     #910,W0
008EA:  REPEAT  #32
008EC:  MOV     [W4++],[W0++]
008EE:  MOV     #912,W0
008F0:  REPEAT  #32
008F2:  MOV     [W5++],[W0++]
008F4:  MOV     #914,W0
008F6:  REPEAT  #32
008F8:  MOV     [W6++],[W0++]
008FA:  MOV     #916,W0
008FC:  REPEAT  #32
008FE:  MOV     [W7++],[W0++]
00900:  MOV     #918,W0
00902:  REPEAT  #32
00904:  MOV     [W8++],[W0++]
00906:  MOV     #91A,W0
00908:  REPEAT  #32
0090A:  MOV     [W9++],[W0++]
0090C:  MOV     #91C,W0
0090E:  REPEAT  #32
00910:  MOV     [W10++],[W0++]
00912:  MOV     #91E,W0
00914:  REPEAT  #32
00916:  MOV     [W11++],[W0++]
00918:  MOV     #920,W0
0091A:  REPEAT  #32
0091C:  MOV     [W12++],[W0++]
0091E:  MOV     #922,W0
00920:  REPEAT  #32
00922:  MOV     [W13++],[W0++]
00924:  MOV     #924,W0
00926:  REPEAT  #32
00928:  MOV     [W14++],[W0++]
0092A:  MOV     #926,W0
0092C:  REPEAT  #32
0092E:  MOV     [W15++],[W0++]
00930:  MOV     #928,W0
00932:  REPEAT  #32
00934:  MOV     [W0++],[W0++]
00936:  MOV     #92A,W0
00938:  REPEAT  #32
0093A:  MOV     [W1++],[W0++]
0093C:  MOV     #92C,W0
0093E:  REPEAT  #32
00940:  MOV     [W2++],[W0++]
00942:  MOV     #92E,W0
00944:  REPEAT  #32
00946:  MOV     [W3++],[W0++]
00948:  MOV     #930,W0
0094A:  REPEAT  #32
0094C:  MOV     [W4++],[W0++]
0094E:  MOV     #932,W0
00950:  REPEAT  #32
00952:  MOV     [W5++],[W0++]
00954:  MOV     #934,W0
00956:  REPEAT  #32
00958:  MOV     [W6++],[W0++]
0095A:  MOV     #936,W0
0095C:  REPEAT  #32
0095E:  MOV     [W7++],[W0++]
00960:  CALL    378
....................

_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 30, 2020 8:40 am     Reply with quote

FYI, using it by pointer does something much more reasonable.

Code:
....................    ShowObjectByPtr (&objects[0]);
*
009C6:  MOV     #800,W4
009C8:  MOV     W4,8D4
009CA:  CALL    3D0
....................   
....................    n = 0;
*
009CE:  CLR     8CE
....................    ShowObjectByPtr (&objects[n]);
009D0:  MOV     8CE,W4
009D2:  MOV     #66,W3
009D4:  MUL.SS  W4,W3,W0
009D6:  MOV     #800,W4
009D8:  ADD     W0,W4,W5
009DA:  MOV     W5,8D4
009DC:  CALL    3D0
....................


(Former instructor soapbox mode...) Pointers in C are one of the main causes for errors and problems... Stray or uninitialized pointers can crash the system. Checking against NULL only proves it's set to something, but does not prove it's pointing to what you want. To make pointers more secure, you'd want to add more to the structure like ID values (or, for critical code, a checksum/CRC or similar), to reduce the chance of a bad pointer getting through.

Pointers are much more efficient and fast, and an easy way to pass something in and have it modified by the function. But, if that speed isn't as important as robustness, eliminating pointers (like many modern languages have done) eliminates those types of errors -- at the cost of extra CPU overhead.

For modifying data, you could do this:

Code:
function (&myStructure);


...or you could safely pass in a copy and update the original like this:

Code:
myStructure = function (myStructure);


The downside of that is you don't have a way to detect errors since you are using the return value for the updated structure. But, adding a simple error code item into the structure takes care of that.

It's slower and produces larger code, but can greatly reduce the amount of hours you might spend tracking down a stray pointer down the line :-)

(Off soapboax now. Sorry, my background was with an embedded operating system and many of our customers ran mission critical code -- traffic controllers and such -- so I got things like this hammered into me early on.)
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 30, 2020 1:42 pm     Reply with quote

CCS provided me an updated DLL to try, and its results are much nicer:

Code:
....................    ShowObject (objects[0]);
*
003EA:  MOV     #800,W0
003EC:  MOV     #8D4,W1
003EE:  REPEAT  #65
003F0:  MOV     [W0++],[W1++]
003F2:  CALL    378
....................   



Code:
....................    int n = 0;
*
003F6:  CLR     8CE
....................    ShowObject (objects[n]);
003F8:  MOV     8CE,W4
003FA:  MOV     #66,W3
003FC:  MUL.SS  W4,W3,W0
003FE:  MOV     #800,W4
00400:  ADD     W0,W4,W0
00402:  MOV     W0,W5
00404:  MOV     #8D4,W4
00406:  REPEAT  #32
00408:  MOV     [W5++],[W4++]
0040A:  CALL    378
....................

_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 12, 2020 9:53 am     Reply with quote

This is expected to be resolved in the next release after 5.092.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 24, 2020 11:43 am     Reply with quote

5.093 has been released. I have confirmed it fixes this issue.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group