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

Error in memset

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



Joined: 21 Feb 2007
Posts: 3

View user's profile Send private message

Error in memset
PostPosted: Tue Feb 27, 2007 4:47 am     Reply with quote

i have a struct gMenue with a size of 0x128 bytes.
When i compile it, i get the following:

memset(&gMenue, 0, sizeof (T_MENUE));
*
018FC: MOVLW 01
018FE: MOVWF 02
01900: MOVLW 28
01902: MOVWF 01
01904: MOVLW 01
01906: MOVWF FEA
01908: MOVLW C4
0190A: MOVWF FE9
0190C: CLRF FEE
0190E: DECFSZ 01,F
01910: BRA 190C
01912: DECFSZ 02,F
01914: BRA 190C

BUT, only the first 0x28 bytes where cleared (Seeing in the debugger). I think the second "decfsz 02,f" is wrong. The register 02 must be loaded with 02 and not with 01.
Is this correct?

Thanks for your help
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 27, 2007 6:40 am     Reply with quote

From the Jan-2007 PICC manual:
Quote:
MEMSET( )
Syntax: memset (destination, value, n)
Parameters: destination is a pointer to memory, value is a 8 bit int, n is a 8 bit int.
Returns: undefined
Note that the size n parameter is only 8 bit, clearing an area of 0x128 bytes doesn't fit.
Studying the generated assembly code it looks like CCS did partially implement the support for a 16-bit size parameter, except for the 'small' off by 1 error.

Which compiler version are you using?
I guess it is a v4.0xx version as v3.249 generates slightly different code for only an 8 bit variable.


Suggested actions:
1) Report this to CCS as a request for enhancement.
2) Create your own large memset routine until CCS releases the new feature.
Code:
void large_memset(char *destination, int8 value, signed int16 size)
{
  while (size > 0)
  {
    memset(destination, value, (int8)size);
    size -= 256;
  }
}
Ralf



Joined: 21 Feb 2007
Posts: 3

View user's profile Send private message

PostPosted: Tue Feb 27, 2007 6:56 am     Reply with quote

Thanks for your help. I reported this to CCS.
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