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

code question

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

code question
PostPosted: Thu Aug 31, 2017 4:09 pm     Reply with quote

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
.................... 
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 5:00 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 6:39 pm     Reply with quote

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.
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Fri Sep 01, 2017 12:26 am     Reply with quote

Be thankful it's not i = i + (int8)1;

:D
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