View previous topic :: View next topic |
Author |
Message |
RUFINOGG
Joined: 15 Jan 2010 Posts: 8
|
Code of sprintf() |
Posted: Mon Dec 13, 2010 7:03 am |
|
|
Where I can find the code of sprintf() implementation in CCS environment ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Mon Dec 13, 2010 9:25 am |
|
|
You can't.
It is worth understanding that the function is 'segmented'. Only parts of the whole code loads, depending on what options are used, so there is no single code for the functions. CCS, don't publish sources for their internal functions.
There have been some alternative printf functions posted in the past and some in the code library, which could be adapted to output to a string.
If you rem out the 'nolist' option in the include file for your processor, the assembler becomes available.
Best Wishes |
|
|
RUFINOGG
Joined: 15 Jan 2010 Posts: 8
|
sprintf() |
Posted: Mon Dec 13, 2010 7:23 pm |
|
|
Ttelmah wrote: | You can't.
It is worth understanding that the function is 'segmented'. Only parts of the whole code loads, depending on what options are used, so there is no single code for the functions. CCS, don't publish sources for their internal functions.
There have been some alternative printf functions posted in the past and some in the code library, which could be adapted to output to a string.
If you rem out the 'nolist' option in the include file for your processor, the assembler becomes available.
Best Wishes |
Thanks for the reply, but I need to pass all arguments to a hexadecimal array, not a string, so I need to modify code:
Code: |
unsigned int32 intxx;
intxx = 0x12345678;
sprintf (array, "% lX intxx ........%s" .......stringXX.... etc.
|
Result:
array [0] = 0x12 NOT in ASCII 0x31, array[1] = 0x32, array[1] = 0x33 ..... .... NOT ASCII
array [1] = 0x34
array [2] = 0x56
array [3] = 0x78
etc ......
...... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Tue Dec 14, 2010 5:15 am |
|
|
And (of course), the old chestnut of unions rears it's head here again:
Code: |
union {
int32 val;
int8 b[4];
} splitter;
splitter.val=0x12345678;
//now splitter.b[0] to b[4] are the array you want _except_ for the byte order....
|
No moving/copying etc necessary. All you are doing is declaring two variable 'types' to occupy the same memory space. An array of four bytes, and the int32 value.
Saves having to relocate the bytes into the array (with make8), but unfortunately, you want the bytes in the reverse order they are stored in memory.
Best Wishes |
|
|
RUFINOGG
Joined: 15 Jan 2010 Posts: 8
|
sprintf() |
Posted: Tue Dec 14, 2010 5:33 am |
|
|
Ttelmah wrote: | And (of course), the old chestnut of unions rears it's head here again:
Code: |
union {
int32 val;
int8 b[4];
} splitter;
splitter.val=0x12345678;
//now splitter.b[0] to b[4] are the array you want _except_ for the byte order....
|
No moving/copying etc necessary. All you are doing is declaring two variable 'types' to occupy the same memory space. An array of four bytes, and the int32 value.
Saves having to relocate the bytes into the array (with make8), but unfortunately, you want the bytes in the reverse order they are stored in memory.
Best Wishes |
Thanks. If I can not change sprintf () this can be a solution to compose a hexadecimal array (string and variables) |
|
|
|