I need to do something 69916 times in a loop.
What is the fastest/simplest way to count that many loop iterations with C51?
I need to do something 69916 times in a loop.
What is the fastest/simplest way to count that many loop iterations with C51?
What's your thought on this, given that ln(69916)/ln2 ~= 16.093 ?
Homework problem?
Best regards, Spehro Pefhany
-- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
I bet it is NOP that you do in a loop.
No slightest clue, eh?
VLV
Actually, 69902. Mistake.
69900 bytes + 16 extra bits.
Don't bet your money, you will lose. I'm sending config file to xc2s50, xilinx's FPGA.
I have two clues:
That won't work, but a friend of mine says that the starting number can be changed somehow, so that it will work, but he is not avaiable right now, and I would also like to here it from somebody else.
I havent even tried that, but it is probably more instructions than on PIC:
incfsz R1,f ;same for R2&R3 goto loop
No.
not exactly as coded, but the idea is right. Try: MOv R1, #LdR1 MOv R2, #LdR2 MOv R3, #LdR3 Loop: Get_SendByteHere ; want this done 69902 times djnz R1, loop djnz R2, loop djnz R3, loop ; This line runs twice, once to loop, once to complete. AllDone:
What numbers : well, the inner loop will spin modulus 256, and you want to fall out the bottom after 69902. That's > 2^16, so the third counter R3 is needed. Consider it in two 'pieces' - a preamble, and then a 2^16, which will be from when R1=R2=0;
69902 -2^16 = 4366, so you need to preload, so that 4366 R1,R2 loops run, before the final 2^16N = 69902 LpR1 = N MOD 256 is 14, so you need 14 extra loads, so you pre-load R1 with 14, to start with.
69902 DIV 256 is 273.0546875, but the .0546875 you have caught with the 14, so you need 273 repeats of the R1 loop.Yields:
N=69902; LpR1 = N % 256; LpR2 = floor((69902 - 2^16) / 256); LpR3 = floor(N/2^16); Check = LpR3*2^16+LpR2*2^8+LpR1;
Those are the loop-counts, the times you 'go-around'. Simple test: if you want the R3 loop to run once, what value do you load ? LpR3 ? or is LdR3 = LpR3 + something ? (etc, for LdR2, LdR1)
You are right is is smaller/faster then your code below.
-jg
To clarify this syntax:
Paste this N=69902; LpR1 = N % 256; LpR2 = floor((69902 - 2^16) / 256); LpR3 = floor(N/2^16); Check = LpR3*2^16+LpR2*2^8+LpR1; disp Check; disp LpR1; disp LpR2; disp LpR3;
into this freeware calculator:
Gives this:
Check = 69902 LpR1 = 14 LpR2 = 17 LpR3 = 1
and I'll leave LdR1,LdR2,LdR3 as an exercise...
R1 =3D 0Eh R2 =3D 12h R3 =3D 02h
[....]
Another way you could do it is unroll the loop so it does two bits per iteration, then your loop counter would fit in 16 bits. (This is probably only worthwhile if the code to do one bit is pretty simple/small.)
-- Wim Lewis , Seattle, WA, USA. PGP keyID 27F772C1 "We learn from history that we do not learn from history." -Hegel
69916 = 227 * 77 * 4
Three nested loops repeated 227, 77 and 4 times will do the job.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.