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 CCS Technical Support

integer create a lot of code

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



Joined: 07 Sep 2003
Posts: 60
Location: Buenos Aires (Argentina)

View user's profile Send private message Send e-mail MSN Messenger

integer create a lot of code
PostPosted: Mon May 02, 2005 4:00 pm     Reply with quote

When I decleare

this structure:

struct control_de_volumen{
int32 entero;
int decimal;
int32 parcial;
int resolucion;
unsigned int16
} volumen[4];

a lot of code is generate:
.................... volumen[canal].decimal++;
0FF0: MOVF xE7,W
0FF2: MULLW 0C
0FF4: MOVF FF3,W
0FF6: CLRF xE9
0FF8: MOVWF xE8
0FFA: MOVLW 04
0FFC: ADDWF xE8,W
0FFE: MOVWF 01
1000: MOVLW 00
1002: ADDWFC xE9,W
1004: MOVWF 03
1006: MOVF 01,W
1008: ADDLW 77
100A: MOVWF FE9
100C: MOVLW 00
100E: ADDWFC 03,W
1010: MOVWF FEA
1012: INCF FEF,F


Why, how I can reduce the code ??
I'll get te same amount of code if
the struct is dont' use ??
_________________
Best Regards
Daniel H. Sagarra
La Plata (Argentina)
Ttelmah
Guest







PostPosted: Mon May 02, 2005 4:48 pm     Reply with quote

The problem here, is using an array, not the structure.
To find the element addressed by 'canal', the compiler has to take this value, and multiply it by the size of the structure, then add the offset to the byte required, put this result into the indirect addressing registers, and use these to actually retrieve the value.
If you code with a fixed index, as (for instance):
volumen[0l].decimal++;

The compiler can 'solve' where this is when the code is generated, and the result will be a couple of instructions. However as soon as you use a variable to access an array, there is this type of code.

Best Wishes
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