|
|
View previous topic :: View next topic |
Author |
Message |
PaulAntonucci
Joined: 30 Dec 2003 Posts: 1 Location: Watertown, MA
|
Efficient copying of structures |
Posted: Tue Dec 30, 2003 11:17 am |
|
|
Hello:
I have the following problem: I need to very quickly copy a structure. I have an older version of my program which uses an 8 byte structure and a "copy" compiles nicely and efficiently as follows:
struct object_descriptor {
byte y_start;
byte y_end;
long x_up_total;
long x_down_total;
byte previous_x_up;
byte previous_x_down;
};
struct object_descriptor C1_object1, C1_object2, C2_object1, C2_object2;
.................... C2_object2 = C2_object1;
05D0: MOVF 36,W
05D1: MOVWF 3E
05D2: MOVF 37,W
05D3: MOVWF 3F
05D4: MOVF 38,W
05D5: MOVWF 40
05D6: MOVF 39,W
05D7: MOVWF 41
05D8: MOVF 3A,W
05D9: MOVWF 42
05DA: MOVF 3B,W
05DB: MOVWF 43
05DC: MOVF 3C,W
05DD: MOVWF 44
05DE: MOVF 3D,W
05DF: MOVWF 45
However, I recently expanded the data structure to 9 bytes (by adding bit fields) and the copy sets up pointers and is very time consuming as follows:
struct object_descriptor {
byte y_start;
byte y_end;
long x_up_total;
long x_down_total;
byte previous_x_up;
byte previous_x_down;
short field_index, y_start_overflow, y_end_overflow, object_started;
};
.................... C1_object2 = C1_object1;
0B32: MOVLW 2F
0B33: MOVWF 64
0B34: MOVLW 26
0B35: MOVWF 63
0B36: MOVLW 09
0B37: MOVWF 78
0B38: MOVF 63,W
0B39: MOVWF 04
0B3A: MOVF 00,W
0B3B: MOVWF 77
0B3C: MOVF 64,W
0B3D: MOVWF 04
0B3E: MOVF 77,W
0B3F: MOVWF 00
0B40: INCF 63,F
0B41: INCF 64,F
0B42: DECFSZ 78,F
0B43: GOTO 338
Do you have a solution for this problem ?
Thanks !!
Paul Antonucci _________________ Paul Antonucci
Paul@AlbertisWindow.com |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 30, 2003 12:40 pm |
|
|
You may have to manually copy each element of the structure.
In terms of C code, it's messy, but it does produce the efficient
assembly code that you desire. Example:
C1_object2.y_start = C1_object1.y_start;
.
.
.
C1_object2.field_index = C1_object1.field_index;
etc. |
|
|
KerryW Guest
|
MEMCPY |
Posted: Tue Dec 30, 2003 12:45 pm |
|
|
Try
MEMCPY(C1_object2, C1_object1, SIZEOF(C1_object1); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 30, 2003 12:58 pm |
|
|
I looked at memcpy before I posted my answer.
The problem with memcpy is that it produces the same
code (with pointers) that he doesn't like. |
|
|
|
|
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
|