|
|
View previous topic :: View next topic |
Author |
Message |
alanp
Joined: 27 Oct 2005 Posts: 6
|
Optimised ways to call functions? |
Posted: Wed Oct 25, 2006 5:44 pm |
|
|
Hello,
I'm after some help trying to convert some code from the HiTech C compiler to the CCS.
The code has been optimised to do things between interrupts so there is a mixture of both C and asm.
The HiTech compiler uses the W register to move information to and from functions. Thus the code is very compact. For example to get something from the EEPROM and send it, the eep_read function has been optimised in asm so it doesn't have to return a value (because it is already in the W register). This listing is from the .LST file:
Code: |
924 403: sendc(eep_read(0x1f));
925 0477 301F movlw 31
926 0478 1283 bcf 3,5
927 0479 21BD call _eep_read
928 047A 22FB call _sendc
231 char eep_read(char addr)
232 {
233 01BD _eep_read
234 TMR0IE = 0;
235 01BD 128B bcf 11,5
236 01BE 1683 bsf 3,5 ;Bank 1
237 01BF 009B movwf 27 ;W contains the address to read
238 01C0 141C bsf 28,0 ;Read EE
239 01C1 081A movf 26,w ;Move data to W
240 TMR0IE = 1;
241 01C2 168B bsf 11,5
242 }
243 01C3 1283 bcf 3,5
244 01C4 0008 return
|
A similar call in CCS is shown below:
Code: |
.................... sendc(eep_read(0x1f));
02D1: MOVLW 1F
02D2: MOVWF 5F
02D3: CALL 0C9
02D4: MOVF 21,W
02D5: MOVWF 5E
02D6: MOVWF 60
02D7: CALL 132
....................
.................... char eep_read(char addr)
.................... {
.................... char ret;
.................... TMR0IE = 0;
*
00C9: BCF 0B.5
.................... ret = read_eeprom(addr);
00CA: MOVF 5F,W
00CB: BSF 03.5
00CC: MOVWF 1B
00CD: BCF 1C.7
00CE: BSF 1C.0
00CF: MOVF 1A,W
00D0: BCF 03.5
00D1: MOVWF 60
.................... TMR0IE = 1;
00D2: BSF 0B.5
.................... return (ret);
00D3: MOVF 60,W
00D4: MOVWF 21
.................... }
00D5: RETLW 00
|
The CCS compiler moves all the variables to RAM before calling the function. The function then has to get the variables out of RAM, put the result back into RAM, and then read from RAM when back in the main function.
There are 12 instructions for the HiTech compilers and 20 for CCS, with a little more tinkering I could reduce the CCS by a couple. With would still leave an extra 50% with CCS.
Does anybody use any techniques that would allow functions to be called in a more effiecent way??
Many thanks
alanp |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 26, 2006 1:04 am |
|
|
I don't think there's any way to force the compiler to optimize the
code to use the W register instead of RAM, to pass and return a
single byte value.
What PIC are you using ? I'm not able to duplicate your code
unless I know that. |
|
|
Guest
|
|
Posted: Thu Oct 26, 2006 2:09 am |
|
|
Thanks for the reply PCM Programmer,
At the moment I'm using the 16F636.
While I understand that I could put the function in-line, I would rather not because of space.
I wasn't really expecting a positive outcome because of the way the CCS compiler works.
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 26, 2006 2:31 am |
|
|
By passing and returning everything in a global variable, I was able
to reduce the eeprom function by 2 ROM words. Not very much. |
|
|
|
|
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
|