|
|
View previous topic :: View next topic |
Author |
Message |
Todd C. Micallef Guest
|
Assigning values to Pointers |
Posted: Thu Mar 21, 2002 6:14 am |
|
|
This is an example from version 3.068...
.................... *add=0;
043A: MOVF 68,W
043B: MOVWF 04
043C: BCF 03.7
043D: BTFSC 69.0
043E: BSF 03.7
043F: CLRF 00
..................
And this is from the latest version...3.080
.................... *add=0;
0857: MOVF 6A,W
0858: MOVWF 04
0859: BCF 03.7
085A: BTFSC 6B.0
085B: BSF 03.7
085C: INCF 04,F
085D: CLRF 00
085E: DECF 04,F
085F: CLRF 00
..................
Why the extra code? This reoccurs with other pointer assignments too.
I checked the entire listing, and it only seems to affect the assignment of values to pointers.
Any help would be appreciated.
___________________________
This message was ported from CCS's old forum
Original Post ID: 3374 |
|
|
Tomi Guest
|
Re: Assigning values to Pointers |
Posted: Thu Mar 21, 2002 8:58 am |
|
|
Don't ask why but the difference is that 3.068 uses (*add) as char (only one byte is cleared) and the 3.080 uses it as 16-bit int (two consecutive bytes are cleared). What is your type declaration for add (char *, int16 *, etc.) ?
:=This is an example from version 3.068...
:=.................... *add=0;
:=043A: MOVF 68,W
:=043B: MOVWF 04
:=043C: BCF 03.7
:=043D: BTFSC 69.0
:=043E: BSF 03.7
:=043F: CLRF 00
:=..................
:=
:=And this is from the latest version...3.080
:=.................... *add=0;
:=0857: MOVF 6A,W
:=0858: MOVWF 04
:=0859: BCF 03.7
:=085A: BTFSC 6B.0
:=085B: BSF 03.7
:=085C: INCF 04,F
:=085D: CLRF 00
:=085E: DECF 04,F
:=085F: CLRF 00
:=..................
:=
:=Why the extra code? This reoccurs with other pointer assignments too.
:=
:=I checked the entire listing, and it only seems to affect the assignment of values to pointers.
:=
:=Any help would be appreciated.
___________________________
This message was ported from CCS's old forum
Original Post ID: 3379 |
|
|
Todd C. Micallef Guest
|
Re: Assigning values to Pointers |
Posted: Thu Mar 21, 2002 9:31 am |
|
|
it is declared as a long.
long add=0x100;
later down the code it is used as a pointer
add+=USB_Buffer;
for (i=0;i<40;i++) {
*add=0;
add++;
}
The code is from the USB Beta files. They actually work in 3.068 but the last couple versions won't the chip enumerate.
I've been looking at the difference in compiled code but it has not pointed anything out thus far. I wasn't certain if the code change was for the better or worse.
Thanks..
:=Don't ask why but the difference is that 3.068 uses (*add) as char (only one byte is cleared) and the 3.080 uses it as 16-bit int (two consecutive bytes are cleared). What is your type declaration for add (char *, int16 *, etc.) ?
:=
:=
:=:=This is an example from version 3.068...
:=:=.................... *add=0;
:=:=043A: MOVF 68,W
:=:=043B: MOVWF 04
:=:=043C: BCF 03.7
:=:=043D: BTFSC 69.0
:=:=043E: BSF 03.7
:=:=043F: CLRF 00
:=:=..................
:=:=
:=:=And this is from the latest version...3.080
:=:=.................... *add=0;
:=:=0857: MOVF 6A,W
:=:=0858: MOVWF 04
:=:=0859: BCF 03.7
:=:=085A: BTFSC 6B.0
:=:=085B: BSF 03.7
:=:=085C: INCF 04,F
:=:=085D: CLRF 00
:=:=085E: DECF 04,F
:=:=085F: CLRF 00
:=:=..................
:=:=
:=:=Why the extra code? This reoccurs with other pointer assignments too.
:=:=
:=:=I checked the entire listing, and it only seems to affect the assignment of values to pointers.
:=:=
:=:=Any help would be appreciated.
___________________________
This message was ported from CCS's old forum
Original Post ID: 3382 |
|
|
Tomi Guest
|
Re: Assigning values to Pointers |
Posted: Thu Mar 21, 2002 10:31 pm |
|
|
<font face="Courier New" size=-1>I think the second list (add handled as int16*) is not simply worse for you but it is dangerous.
In the standard C your code:
for (i=0;i<40;i++) {
*add=0;
add++;
}
will clear 80(!) bytes because the ++ operator is implemented as "move to the next element" so add 2 in your case. This means that any variables declared AFTER the 40-byte buffer will be corrupted.
If you want to clear a 40-bytes buffer only, it would be better to declare add as char * (and to check the list file again ) or to run the for cycle to 20 (but it is a dirty solution).
:=it is declared as a long.
:= I wasn't certain if the code change was for the better or worse.
___________________________
This message was ported from CCS's old forum
Original Post ID: 3389 |
|
|
Todd C. Micallef Guest
|
Re: Assigning values to Pointers |
Posted: Fri Mar 22, 2002 4:53 am |
|
|
Thanks Tomi!
I wasn't concentrating on the total number of bytes involved. I need to brush up on some ASM programming. Unfortunately that's why I have this C compiler so I wouldn't have to do much.:)
:=<font face="Courier New" size=-1>I think the second list (add handled as int16*) is not simply worse for you but it is dangerous.
:=In the standard C your code:
:=for (i=0;i<40;i++) {
:=*add=0;
:=add++;
:=}
:=will clear 80(!) bytes because the ++ operator is implemented as "move to the next element" so add 2 in your case. This means that any variables declared AFTER the 40-byte buffer will be corrupted.
:=If you want to clear a 40-bytes buffer only, it would be better to declare add as char * (and to check the list file again
:=
:=:=it is declared as a long.
:=:= I wasn't certain if the code change was for the better or worse.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 3394 |
|
|
|
|
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
|