![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
soonc
Joined: 03 Dec 2013 Posts: 215
|
code question |
Posted: Thu Aug 31, 2017 4:09 pm |
|
|
Recently I've been using the mmcsd.c library code to directly write to a 2GB SD card.
It's working.
During my debugging sessions I ran in this line of code:
for(i = 0; i < MMCSD_MAX_BLOCK_SIZE; i += 1)
my question why use i += 1 when i++ will produce less code ?
Code: |
.................... for(i = 0; i < MMCSD_MAX_BLOCK_SIZE; i += 1)
0B18A: CLR 1AE2
0B18C: MOV 1AE2,W4
0B18E: MOV #200,W3
0B190: CP W3,W4
0B192: BRA LEU,B1B0
.................... {
.................... MMCSD_SPI_XFER(ptr[i]);
0B194: MOV 1AE2,W0
0B196: ADD 1ADC,W0
0B198: MOV.B [W0],W5L
0B19A: MOV #0,W1
0B19C: MOV #8,W2
0B19E: MOV.B W5L,W0L
0B1A0: CLR.B 1
0B1A2: CALL 312C
0B1A6: MOV 1AE2,W4
0B1A8: ADD W4,#1,W0
0B1AA: MOV W0,1AE2
0B1AC: GOTO B18C
|
Code: |
.................... for(i = 0; i < MMCSD_MAX_BLOCK_SIZE; i++)
0B18A: CLR 1AE2
0B18C: MOV 1AE2,W4
0B18E: MOV #200,W3
0B190: CP W3,W4
0B192: BRA LEU,B26C
.................... {
.................... MMCSD_SPI_XFER(ptr[i]);
0B194: MOV 1AE2,W0
0B196: ADD 1ADC,W0
0B198: MOV.B [W0],W5L
0B19A: MOV #0,W1
0B19C: MOV #8,W2
0B19E: MOV.B W5L,W0L
0B1A0: CLR.B 1
0B1A2: CALL 312C
....................
|
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Thu Aug 31, 2017 5:00 pm |
|
|
All programmers have their style of cutting code. This code cutter uses what he either was taught or found to work for him.
You can program either for smaller code( saves memory) or for speed of execution.
Perhaps his code does execute faster, I don't know. What we do know is his code does work !!
Jay |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 31, 2017 6:39 pm |
|
|
I just did a text search of the \Examples and \Drivers folders for "i += 1".
It's used 2x in mmcsd.c and 12x in fat.c, and in no other files. |
|
![](templates/subSilver/images/spacer.gif) |
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Fri Sep 01, 2017 12:26 am |
|
|
Be thankful it's not i = i + (int8)1;
:D |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|