|
|
View previous topic :: View next topic |
Author |
Message |
Calamar
Joined: 07 Sep 2003 Posts: 60 Location: Buenos Aires (Argentina)
|
integer create a lot of code |
Posted: Mon May 02, 2005 4:00 pm |
|
|
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
|
|
Posted: Mon May 02, 2005 4:48 pm |
|
|
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 |
|
|
|
|
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
|