August 24th, 2011, 09:45 AM
When does the loop terminate? ?
I am developing software driver for NOR Flash EEPROM.I was searching in internet for available drivers, i came across the followed link:
While i was going through write flash function:
BOOL WriteFlashJ3_1x16(DWORD dwDest, DWORD dwSource, DWORD dwLength);
I have got one doubt may be i might have analysed wrongly , i could not understand how and when we will come out of the loop.
In the link Code Start Line No : 403 and Code End Line No:409
ulEndCount = ulCount + FLASH_BUFFER_SIZE;
pusDest[ulCount>>1] = pusSource[ulCount>>1];
ulCount += sizeof(USHORT);
} while(ulCount < ulEndCount);
Because the loop runs while the ulCount is lesser than ulEndCount.But when i observed i found that ulCount is always lesser than ulEndCount.
So When does the loop terminate??
August 24th, 2011, 01:03 PM
You more or less answered it self: "the loop runs while the ulCount is lesser than ulEndCount"
So when ulCount gets equal or greater it will stop the loop.
Where in the code did you check the ulCount? after the loop?
August 24th, 2011, 08:08 PM
When does the loop terminate ??
Thanks for the response.
value of sizeof(USHORT)= 2 (If i am not wrong)
And if you observe the code ulCount is assigned "0" value.And FLASH_BUFFER_SIZE=32,
ulEndCount = 0 (ulCount) +32 (FLASH_BUFFER_SIZE);
After first loop iteration:.
ulCount += sizeof(USHORT); is as followed
so since the value of ulCount (2) is lessthan ulEndCount(32)
loop is executed again
and it will be right shifted to 1 bit position in the next loop iteration and now the value becomes 1 ( 2=0010 and when shifted 0010 >>1 = 0001)
and again ulCount= 1 (ulCount=1 after first iteratio) + 2(sizeof(USHORT));
So now ulCount=3;
Even now also the value of ulCount (3) is lessthan ulEndCount(32)
so loop is executed again
and it will be right shifted to 1 bit position in the next loop iteration and now the value becomes 1 ( 3=0011 and when shifted 0011 >>1 = 0001)
Thus ulCount is always 1 & 3 and is not going to increase
so my question is when does the loop terminate ?
August 25th, 2011, 06:09 PM
Would recommend that you try to insert some (debug) print call to check what the value of ulCount really is.
Or is all the values you posted a output from that kind of test?
>> alone should not save any value back into the variable (ulCount), for that effect you will need to write it like >>=